Connection to OpcUA-Server failed, because of "No suitable UserTokenPolicy"

2.2k Views Asked by At

I'm new to OpcUA and use Open62541 v3.0 - rc2.

I'm trying to connect to an OpcUA-Server on an B&R Device.

When I'm trying to connect to the Server (with username and Password) i get this message "No suitable UserTokenPolicy found for the possible endpoints" and this return-value UA_STATUSCODE_BADINTERNALERROR.

UA_StatusCode statusCode = UA_Client_connect_username(client,endpoint,"user","password");

A connection with UAExpert to the Device is working correctly.

The log of UAExpert prints following message:

Security policy: 'http://opcfoundation.org/UA/SecurityPolicy#None'

Connection-Settings in UA-Expert: Connection-Settings in UA-Expert

Why can't I connect to the Server with the following code?

#include "open62541.h"

UA_Logger logger = UA_Log_Stdout;

int main(void) {
    const char* endpoint = "opc.tcp://br-automation:4840";

    UA_ClientConfig config = UA_ClientConfig_default;
    UA_Client *client = UA_Client_new(config);

    UA_StatusCode statusCode = UA_Client_connect_username(client,endpoint,"user","password");

    if(statusCode != UA_STATUSCODE_GOOD){
        UA_LOG_ERROR(logger, UA_LOGCATEGORY_CLIENT, "Not connected. Got StatusCode 0x%X",statusCode);
    }
    else{
        UA_LOG_INFO(logger,UA_LOGCATEGORY_CLIENT,"Connected");
    }

    UA_Client_delete(client);

    return statusCode;
}

UA_Client_getEndpoints() gives the following result:

7 endpoints found
URL of endpoint 0 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#None Security-Mode: 1
    UserTokenType 1
    UserTokenType 1
URL of endpoint 1 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15 Security-Mode: 2
    UserTokenType 1
    UserTokenType 1
URL of endpoint 2 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15 Security-Mode: 3
    UserTokenType 1
    UserTokenType 1
URL of endpoint 3 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256 Security-Mode: 2
    UserTokenType 1
    UserTokenType 1
URL of endpoint 4 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256 Security-Mode: 3
    UserTokenType 1
    UserTokenType 1
URL of endpoint 5 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 Security-Mode: 2
    UserTokenType 1
    UserTokenType 1
URL of endpoint 6 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 Security-Mode: 3
    UserTokenType 1
    UserTokenType 1
1

There are 1 best solutions below

0
On

Please refer to this Open62541 GitHub issue : 'Connect to the selected server with the given username and password'