title: Connection to OpcUA-Server failed, because of "No suitable UserTokenPolicy"
body: <p>I'm new to OpcUA and use Open62541 v3.0 - rc2.</p>
  
  <p>I'm trying to connect to an OpcUA-Server on an B&amp;R Device.</p>
  
  <p>When I'm trying to connect to the Server (with username and Password) i get this message <code>"No suitable UserTokenPolicy found for the possible endpoints"</code> and this return-value <code>UA_STATUSCODE_BADINTERNALERROR</code>.</p>
  
  <pre><code>UA_StatusCode statusCode = UA_Client_connect_username(client,endpoint,"user","password");
  </code></pre>
  
  <p>A connection with UAExpert to the Device is working correctly.</p>
  
  <p>The log of UAExpert prints following message:</p>
  
  <blockquote>
    <p>Security policy: '<a href="http://opcfoundation.org/UA/SecurityPolicy#None" rel="nofollow noreferrer">http://opcfoundation.org/UA/SecurityPolicy#None</a>'</p>
  </blockquote>
  
  <p>Connection-Settings in UA-Expert:
  <a href="https://i.stack.imgur.com/l1IDs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l1IDs.png" alt="Connection-Settings in UA-Expert"></a></p>
  
  <p>Why can't I connect to the Server with the following code?</p>
  
  <pre><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;
  }
  </code></pre>
  
  <p>UA_Client_getEndpoints() gives the following result:</p>
  
  <pre><code>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
  </code></pre>