Azure / dps-keygen

Helper tool to deal with the device keys :closed_lock_with_key:
MIT License
24 stars 16 forks source link

When creating the connection string I get 401000 error #7

Closed eskandari closed 5 years ago

eskandari commented 5 years ago

Here is how I call it:

first generate device key: dps-keygen 2......deleted....= 87f4d9a8-3b71-41a7-94f5-3e7461a7869d

Azure IoT DPS Symetric Key Generator v0.2.1 MASTER-KEY: 2YNErCL....deleted....= BASE-DEVICE-ID: 87f4d9a8-3b71-41a7-94f5-3e7461a7869d

please find the device key below. M5UWhqRBmUl.....BOt2PtHnT0stYfYBo=

then for getting the connection string I am getting below error:

dps-keygen M5UWhqRBmUleZsb7w4CKOJh2fSBOt2PtHnT0stYf.....= 87f4d9a8-3b71-41a7-94f5-3e7461a7869d 0ne00043291

Azure IoT DPS Symetric Key Generator v0.2.1 MASTER-KEY: M5UWhqRBmUleZsb7w4CKOJh2fSBOt2PtHn.....= BASE-DEVICE-ID: 87f4d9a8-3b71-41a7-94f5-3e7461a7869d { errorCode: 401000, trackingId: '0a65127b-2c0a-4112-8fa2-eff426cb6b5e', message: 'Unauthorized', timestampUtc: '2019-02-02T23:06:34.4415072Z' }

obastemur commented 5 years ago

Under the device explorer, find the ~unauthorized~ unassociated devices and associate the device.

eskandari commented 5 years ago

Tnx for promot response. I navigated to the device explorer, select raspberry pi, but I can't find the unauthorized devices.

obastemur commented 5 years ago

untitled

Please see the attachment.

eskandari commented 5 years ago

there is no device under unassociated devices please see below 2019-02-02 18_33_55-explorer _ sample devkits g1x17il61w

image

eskandari commented 5 years ago

should I open a new issue with more descriptions?

obastemur commented 5 years ago

Can you browse into that device’s panel and click open to ‘connect’ button up-right and use the creds there?

obastemur commented 5 years ago

I’ve deleted your last share that includes device creds. Could you try the info there to authenticate?

obastemur commented 5 years ago

In other words, your mistake is ... using device key as if it is a master key. Use the creds there directly to create a connection string

eskandari commented 5 years ago

I just followed the documentation. here is the link: https://www.npmjs.com/package/dps-keygen

first i used below to get the device key: dps-keygen <Primary/Secondary_Key(GroupSAS)>

then after getting the device key, then I used below to get connection string: dps-keygen device key device_id scope_id

Not sure where is my mistake.

obastemur commented 5 years ago

Sorry for the confusion. The first command is used for account master key to create device authentication keys. Since you were already using an auth. key from device window, there is no need to execute the first command.

You can find your master key under admin settings.

I appreciate if you check and confirm this works for you

obastemur commented 5 years ago

Side question; what environment you are working on? I’m trying to understand the reason for using connection string

eskandari commented 5 years ago

so if I understand correctly, i should use below: dps-keygen masterKey device_id scope_id getting the masterKey from: Administration => Device Connection => Primary key

Even with this I am getting the same error code.

I am running "dps-keygen" on my surface pro, once I have the connection string, i would push it to c# code and publish and push it to my raspberry pi which running rasbien.

appreciate your patience.

obastemur commented 5 years ago

it's dps-keygen <device key> <device id> <scope_id> So, you shouldn't use your master key and you shouldn't call the first command that doesn't require the scope id.

dps-keygen 2YNErCL.............GSbfP8h8= 87f4d9a8-3b.........461a7869d 0ne00043291

eskandari commented 5 years ago

this worked for me dps-keygen

thanks for your help. I think info here is confusing:https://www.npmjs.com/package/dps-keygen

obastemur commented 5 years ago

Glad you got it working now.

@sandeeppujar FYI. I’m open for documentation suggestions and contribution