-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Task] New Keycloak Device Flow #400
Comments
related IndustryFusion#400 Signed-off-by: Oguzcan Kirmemis <[email protected]>
@wagmarcel I have created a reference implementation at #401. This PR should not break the current applications but allow us to migrate other services(mostly mqtt-gateway) step by step to the new flow. |
Here is the example flow, first the user requests a device-onboarding token: foo@bar:~$ curl -X POST "http://keycloak.local/auth/realms/iff/protocol/openid-connect/token" \
-d "client_id=device-onboarding" \
-d "username=realm_user" \
-d "password=HqYOBCcZypuhtPzzJltxjdp0TqgBbIiy" \
-d "grant_type=password" {
"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJseHRIcnRUcGRmc1dXQm1QU29Zal9jNnRoNVFfenM5azVNY0Iwc1ZIUmJJIn0.eyJleHAiOjE2ODkzMzU2ODIsImlhdCI6MTY4OTMzNTM4MiwianRpIjoiZDVkNjdiMmEtMzQ0ZC00OTZhLWI1MWUtYzlhZDAyNDM5ZjhkIiwiaXNzIjoiaHR0cDovL2tleWNsb2FrLmxvY2FsL2F1dGgvcmVhbG1zL2lmZiIsInN1YiI6IjU0MmY5MmJiLTZmN2MtNDg1Yy1iYjIxLThlM2RhMWViMWQ4NyIsInR5cCI6IkJlYXJlciIsImF6cCI6ImRldmljZS1vbmJvYXJkaW5nIiwic2Vzc2lvbl9zdGF0ZSI6IjdmMTAxZDYwLTExNDMtNDJmYS05ZWE4LWNmNTZlNDA1MThkZCIsInNjb3BlIjoiIiwic2lkIjoiN2YxMDFkNjAtMTE0My00MmZhLTllYTgtY2Y1NmU0MDUxOGRkIn0.PgGuTtdAHLVOWFCvntNZbM1kmub-kfQf3Xv6PJ-2ZjPSeKWvXA4dc6pXQKfb09dVt8hO0YCP2gyiE8I0SGyH5OrhK_TCG9FZOQ3aUO0-68lRJo9b-KNJRBBX6JPiVcp8evRBz2gHulcp7BTE0ND83GX6t7DPe75Nt_N_VmeavVKdIQrRCUEyKFdanNImgsg1Wg5SCr_IU0E0VdRQByl2q-X1EdBhSGC16EhVlW8NwTUTr2VWnasUubpcvYt7P8TU1l9WukSTbraz-8Ghg5cuoSKgZKjQT8vljXsk5jN2z4jKqjooZilUrUisCV9tHR0YSYofEypbxPv7FacdcolrMw",
"expires_in":3600,
"refresh_expires_in":60,
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI1NDhjZTVhYy0yMjhkLTQ3ZmUtYTAxZS1jMmRjNmQ4N2VmODEifQ.eyJleHAiOjIwMDQ2OTUzODIsImlhdCI6MTY4OTMzNTM4MiwianRpIjoiYmRhOGMwYzItNzFlNC00YmI3LWI0ZjMtYjEyZDdiNWY1MjM0IiwiaXNzIjoiaHR0cDovL2tleWNsb2FrLmxvY2FsL2F1dGgvcmVhbG1zL2lmZiIsImF1ZCI6Imh0dHA6Ly9rZXljbG9hay5sb2NhbC9hdXRoL3JlYWxtcy9pZmYiLCJzdWIiOiI1NDJmOTJiYi02ZjdjLTQ4NWMtYmIyMS04ZTNkYTFlYjFkODciLCJ0eXAiOiJSZWZyZXNoIiwiYXpwIjoiZGV2aWNlLW9uYm9hcmRpbmciLCJzZXNzaW9uX3N0YXRlIjoiN2YxMDFkNjAtMTE0My00MmZhLTllYTgtY2Y1NmU0MDUxOGRkIiwic2NvcGUiOiIiLCJzaWQiOiI3ZjEwMWQ2MC0xMTQzLTQyZmEtOWVhOC1jZjU2ZTQwNTE4ZGQifQ.sUE0oIJ9Smm024hJwugDH6AWs5noUEQslKC80gJq0Zc",
"token_type":"Bearer",
"not-before-policy":0,
"session_state":"7f101d60-1143-42fa-9ea8-cf56e40518dd",
"scope":""
} The resulting token will be minimal: {
"iat": 1689336564,
"jti": "10da8068-795a-4ed1-8e43-ff8de460bdff",
"iss": "http://keycloak.local/auth/realms/iff",
"aud": "http://keycloak.local/auth/realms/iff",
"sub": "testdevice",
"typ": "Offline",
"azp": "device-onboarding",
"session_state": "2242f745-ce19-46dd-9441-7a95d6f04cde",
"scope": "oisp-frontend device_id gateway mqtt-broker offline_access type",
"sid": "2242f745-ce19-46dd-9441-7a95d6f04cde"
} Also notice that there is a refresh token which only has 60 seconds expire time. This is a limitation in Keycloak, we cannot remove refresh tokens entirely, nevertheless the only thing this refresh token can do is to get another device onboarding token. There should be a workaround to also set the expire time to 0 if desired. With the onboarding token, we make a token exchange request to get a new device token: foo@bar:~$ token=eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJseHRIcnRUcGRmc1dXQm1QU29Zal9jNnRoNVFfenM5azVNY0Iwc1ZIUmJJIn0.eyJleHAiOjE2ODkzMzU2ODIsImlhdCI6MTY4OTMzNTM4MiwianRpIjoiZDVkNjdiMmEtMzQ0ZC00OTZhLWI1MWUtYzlhZDAyNDM5ZjhkIiwiaXNzIjoiaHR0cDovL2tleWNsb2FrLmxvY2FsL2F1dGgvcmVhbG1zL2lmZiIsInN1YiI6IjU0MmY5MmJiLTZmN2MtNDg1Yy1iYjIxLThlM2RhMWViMWQ4NyIsInR5cCI6IkJlYXJlciIsImF6cCI6ImRldmljZS1vbmJvYXJkaW5nIiwic2Vzc2lvbl9zdGF0ZSI6IjdmMTAxZDYwLTExNDMtNDJmYS05ZWE4LWNmNTZlNDA1MThkZCIsInNjb3BlIjoiIiwic2lkIjoiN2YxMDFkNjAtMTE0My00MmZhLTllYTgtY2Y1NmU0MDUxOGRkIn0.PgGuTtdAHLVOWFCvntNZbM1kmub-kfQf3Xv6PJ-2ZjPSeKWvXA4dc6pXQKfb09dVt8hO0YCP2gyiE8I0SGyH5OrhK_TCG9FZOQ3aUO0-68lRJo9b-KNJRBBX6JPiVcp8evRBz2gHulcp7BTE0ND83GX6t7DPe75Nt_N_VmeavVKdIQrRCUEyKFdanNImgsg1Wg5SCr_IU0E0VdRQByl2q-X1EdBhSGC16EhVlW8NwTUTr2VWnasUubpcvYt7P8TU1l9WukSTbraz-8Ghg5cuoSKgZKjQT8vljXsk5jN2z4jKqjooZilUrUisCV9tHR0YSYofEypbxPv7FacdcolrMw
foo@bar:~$ curl -X POST "http://keycloak.local/auth/realms/iff/protocol/openid-connect/token" \
-d "client_id=device-onboarding" \
-d "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
-d "subject_token=${token}" \
-d "requested_token_type=urn:ietf:params:oauth:token-type:refresh_token" \
-d "audience=device" \
-H "X-GatewayID: testgw" \
-H "X-DeviceID: testdevice" \
-H "X-Access-Type: device" \
-H "X-DeviceUID: uid" {
"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJseHRIcnRUcGRmc1dXQm1QU29Zal9jNnRoNVFfenM5azVNY0Iwc1ZIUmJJIn0.eyJleHAiOjE2ODk0MjM2MDQsImlhdCI6MTY4OTMzNzIwNCwianRpIjoiODg0NTc4ZGYtNjY2Mi00NDFjLWFlNzAtYmZlOTZlZDE5MzQ3IiwiaXNzIjoiaHR0cDovL2tleWNsb2FrLmxvY2FsL2F1dGgvcmVhbG1zL2lmZiIsImF1ZCI6WyJvaXNwLWZyb250ZW5kIiwibXF0dC1icm9rZXIiLCJkZXZpY2UiXSwic3ViIjoidGVzdGRldmljZSIsInR5cCI6IkJlYXJlciIsImF6cCI6ImRldmljZS1vbmJvYXJkaW5nIiwic2Vzc2lvbl9zdGF0ZSI6IjIyNDJmNzQ1LWNlMTktNDZkZC05NDQxLTdhOTVkNmYwNGNkZSIsInNjb3BlIjoib2lzcC1mcm9udGVuZCBkZXZpY2VfaWQgZ2F0ZXdheSBtcXR0LWJyb2tlciBvZmZsaW5lX2FjY2VzcyB0eXBlIiwic2lkIjoiMjI0MmY3NDUtY2UxOS00NmRkLTk0NDEtN2E5NWQ2ZjA0Y2RlIiwiZGV2aWNlX2lkIjoidGVzdGRldmljZSIsIn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peaQYFGSznMItg35K3-3fNakfc",
"token_type":"Bearer",
"not-before-policy":0,
"session_state":"2242f745-ce19-46dd-9441-7a95d6f04cde",
"scope":"oisp-frontend device_id gateway mqtt-broker offline_access type"
} The header parameter descriptions:
The resulting token is a full capable device token, that is compatible with OISP and has a offline refresh token: {
"exp": 1689423604,
"iat": 1689337204,
"jti": "884578df-6662-441c-ae70-bfe96ed19347",
"iss": "http://keycloak.local/auth/realms/iff",
"aud": [
"oisp-frontend",
"mqtt-broker",
"device"
],
"sub": "testdevice",
"typ": "Bearer",
"azp": "device-onboarding",
"session_state": "2242f745-ce19-46dd-9441-7a95d6f04cde",
"scope": "oisp-frontend device_id gateway mqtt-broker offline_access type",
"sid": "2242f745-ce19-46dd-9441-7a95d6f04cde",
"device_id": "testdevice",
"type": "device",
"gateway": "testgw",
"accounts": [
"id": "c6c1c8fe-5e22-4e88-881e-1103fe07e85b",
"role": "device"
]
} In future, the "accounts" field will be also removed. In general any legacy field coming from OISP that is no longer needed will be removed. |
related IndustryFusion#400 Signed-off-by: Oguzcan Kirmemis <[email protected]>
related IndustryFusion#400 Signed-off-by: Oguzcan Kirmemis <[email protected]>
related #400 Signed-off-by: Oguzcan Kirmemis <[email protected]>
DeviceAuthFlow.pdf |
This PR provides a cleaned-up and simplified device agent. The device agent is responsible to connect to MQTT, manage the device token and forwards metrics provided over local udp/tcp protocol. The orginial oisp device admin has been removed and replaced by scripts to manage device onboarding and do test data sending. The original oisp-agent had many ways to communicate to the backend. This has been removed. Now, only the SparkplugB oriented data sending for NGSI-LD data is supported. The agent relies only on two services: (1) Keycloak and (2) MQTT. Since the onboarding only relies on Keycloak, there is a little change on activation procedure. Details are described in the README. Related Epic: IndustryFusion#432 Related User Story: IndustryFusion#446 Related Tasks: IndustryFusion#400, IndustryFusion#445, IndustryFusion#447 Signed-off-by: marcel <[email protected]>
This PR provides a cleaned-up and simplified device agent. The device agent is responsible to connect to MQTT, manage the device token and forwards metrics provided over local udp/tcp protocol. The orginial oisp device admin has been removed and replaced by scripts to manage device onboarding and do test data sending. The original oisp-agent had many ways to communicate to the backend. This has been removed. Now, only the SparkplugB oriented data sending for NGSI-LD data is supported. The agent relies only on two services: (1) Keycloak and (2) MQTT. Since the onboarding only relies on Keycloak, there is a little change on activation procedure. Details are described in the README. Related Epic: IndustryFusion#432 Related User Story: IndustryFusion#446 Related Tasks: IndustryFusion#400, IndustryFusion#445, IndustryFusion#447 Signed-off-by: marcel <[email protected]> fix of copyright years Signed-off-by: marcel <[email protected]>
This PR provides a cleaned-up and simplified device agent. The device agent is responsible to connect to MQTT, manage the device token and forwards metrics provided over local udp/tcp protocol. The orginial oisp device admin has been removed and replaced by scripts to manage device onboarding and do test data sending. The original oisp-agent had many ways to communicate to the backend. This has been removed. Now, only the SparkplugB oriented data sending for NGSI-LD data is supported. The agent relies only on two services: (1) Keycloak and (2) MQTT. Since the onboarding only relies on Keycloak, there is a little change on activation procedure. Details are described in the README. Related Epic: #432 Related User Story: #446 Related Tasks: #400, #445, #447 Signed-off-by: marcel <[email protected]> fix of copyright years Signed-off-by: marcel <[email protected]>
Current device authentication is too complex and needs simplification. The new auth flow I propose:
The text was updated successfully, but these errors were encountered: