ditto icon indicating copy to clipboard operation
ditto copied to clipboard

Creating a connection to hono results in "The supplied authentication is invalid"

Open maximilianschwab opened this issue 8 years ago • 6 comments

I would like to connect to my own hono and ditto instaces and followed the tutorial under https://www.eclipse.org/ditto/2018-05-02-connecting-ditto-hono.html

When I try to connect to hono I get the following error: The supplied authentication is invalid.

I'm using the following DevOps command:

{  
   "targetActorSelection":"/system/sharding/connection",
   "headers":{  

   },
   "piggybackCommand":{  
      "type":"connectivity.commands:createConnection",
      "connection":{  
         "id":"hono-example-connection-123",
         "connectionType":"amqp-10",
         "connectionStatus":"open",
         "failoverEnabled":true,
         "uri":"amqp://consumer@Hono:verysecret@url_to_hono:5671",
         "authorizationSubject": "ditto:ditto",
         "sources":[  
            {  
               "addresses":[  
                  "telemetry/org.eclipse.ditto",
                  "event/org.eclipse.ditto"
               ]
            }
         ],
         "targets":[  
            {  
               "address":"events/twin",
               "topics":[  
                  "_/_/things/twin/events",
                  "_/_/things/live/messages"
               ]
            }
         ]
      }
   }
}

I'm also confused about the authorizationSubject field because this field is not specified in the connections object under https://www.eclipse.org/ditto/basic-connections.html but used in another example to connect to an AMQP 1.0 endpoint https://www.eclipse.org/ditto/connectivity-protocol-bindings-amqp10.html#establishing-connecting-to-an-amqp-10-endpoint

I'm using the default user for hono and ditto, no other users are created by my own.

Help is appreciated! Thank you!

maximilianschwab avatar Aug 01 '18 08:08 maximilianschwab

Hi there.

Ah, regarding the "authorizationSubject" you found an inconsistency - the blog post is right, we replaced the single "authorizationSubject" with the "authorizationContext" containing an array of authorizationSubject Strings. We will fix the outdated documentation.

Are you sure that your Hono instance has this user consumer@Hono configured with that password? I don't know if you have to create the user by yourself or if it automatically exists when starting Hono. Can you authenticate successfully with for example the Hono client using those credentials?

thjaeckle avatar Aug 01 '18 09:08 thjaeckle

Hi again,

the user consumer@Hono is existing and I can connect with this credentials via e.g. the example code for the HonoTelemetryConsumer. Is there an defaul authorizationContext I can use or do I have to generate it? and how does such a authorizationContext look like? I also have to mention that I'm using the basic authentication with the default user ditto and the password ditto for the DevOps command, maybe thats the problem?

maximilianschwab avatar Aug 01 '18 10:08 maximilianschwab

Ah, ok - that are the wrong credentials for sending a DevOps command. Default DevOps command user is: devops and password is foobar (as configured here).

The authorizationContext is a list of subjects which should be applied when consuming messages from Hono. It must contain nginx:ditto if you want to treat all Hono messages in the context of the default Ditto user which is added by default in the .htpasswd

thjaeckle avatar Aug 01 '18 10:08 thjaeckle

Okay, with the new credentials and the authorizationContext I can send commands but when I want to test the connection I get the following response:

{
    "?": {
        "-1": {
            "type": "connectivity.responses:testConnection",
            "status": 409,
            "connectionId": "hono-example-connection-123",
            "testResult": "Connection was already created - no test possible"
        }
    }
}

Does this mean ditto is successfully connected to hono?

maximilianschwab avatar Aug 01 '18 11:08 maximilianschwab

Testing a connection can only be done if it was not yet created. So the connection was created, yes. But in order to find out if it is also connected, you have to send a command of "type": "connectivity.commands:retrieveConnectionMetrics" with "connectionId": "yourId"

As documented here

thjaeckle avatar Aug 01 '18 11:08 thjaeckle

It is working now! Thanky you @thjaeckle !

maximilianschwab avatar Aug 01 '18 14:08 maximilianschwab