1.5 範例
1.5.1 要求
POST https://login.microsoftonline.com/425a8e89-feb9-40d2-9fe5-07fb45419e4b/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Content-Length: 48
grant_type=srv_challenge&windows_api_version=2.0
1.5.2 回應
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Content-Length: 132
"Nonce": "AQABAAAAAADX8GCi6Js6SK82TsD2Pb7rO4c24C6C31bER-HgavkQr-xx11qx0DFkaB6rfm-ikMj\_eUCSQ12bS4Id06ae1CUQjd8jN7xc4uGK-PA6Bj83HyAA"
2 產生裝置 JWT
產生的裝置 JWT 將包含權杖提供者向印表機發出裝置存取權杖所需的資訊。 下一節將詳細說明 JWT 標頭、本文和簽章中所需的資訊。
需要下列 JWT 標頭參數:
resource
string
存取權杖的目標物件。 這是成功完成註冊回應所傳回的 「mcp_svc_resource_id」值。 例如,https://print.print.microsoft.com
client_id
string
已註冊之Azure 應用程式的應用程式(用戶端)識別碼,具有通用列印的 API 許可權。 若要使用適當的 API 許可權建立Azure 應用程式,請參閱 OEM 用戶端識別碼註冊 。
redirect_uri
string
本節中用於 「client_id」之已註冊Azure 應用程式的已設定重新導向 URI。 若要為已註冊的Azure 應用程式設定重新導向 URI,請遵循 OEM 用戶端識別碼註冊 。
string
從成功註冊回應收到的印表機雲端裝置識別碼。
2.3 JWT 簽章
由裝置私密金鑰簽署的 JWT,用來證明要求是從裝置發出的,而不是從不同的要求重新執行。
2.4 範例產生的 JWT
"alg": "RS256",
"typ": "JWT",
"x5c": "MIID8jCCAtqgAwIBAgIQtJE/zIv3C5JOPoIeezhfLzANBgkqhkiG9w0BAQsFADB4MXYwEQYKCZImiZPyLGQBGRYDbmV0MBUGCgmSJomT8ixkARkWB3dpbmRvd3MwHQYDVQQDExZNUy1Pcmdhbml6YXRpb24tQWNjZXNzMCsGA1UECxMkODJkYmFjYTQtM2U4MS00NmNhLTljNzMtMDk1MGMxZWFjYTk3MB4XD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SmyqEZqu0WEoz0FpVYt2pRw9pSb29+Y6n4vWTyWxVI8zMqDieYmaw7uXctqrr"
"request_nonce": "AQABAAAAAADX8GCi6Js6SK82TsD2Pb7rO4c24C6C31bER-HgavkQr-xx11qx0DFkaB6rfm-ikMj\_eUCSQ12bS4Id06ae1CUQjd8jN7xc4uGK-PA6Bj83HyAA",
"grant_type": "device_token",
"resource": "https://microsoft.com/mcp",
"client_id": "1ef464e5-0b61-4c6f-b822-5dc015b9463e",
"redirect_uri": "https://print.print.microsoft.com/",
"iss": "e9a675a2-a7c5-4fe7-8e83-fe1efaf82ec6"
[Signature]
3 要求裝置存取權杖
若要要求裝置權杖,請將 POST 要求傳送至裝置權杖端點,其中包含第 2 節中產生的 JWT 主體。
3.1 HTTP 要求
POST {device_token_url}
{device_token_url}
是從成功註冊回應收到的 URL。
3.2 要求內容類型
application/x-www-form-urlencoded
3.3 要求承載
使用下列名稱/值組形成 URL 編碼格式:
3.5.1 嚴重錯誤
如果印表機已從 UP 入口網站或憑證取消註冊,則印表機將無法取得裝置存取權杖。 在此情況下,裝置權杖端點會傳回 "error": "invalid_grant"
和 "suberror": "device_authentication_failed"
。 此時,印表機應將其狀態重設為 [取消註冊],因為需要重新註冊裝置。
"error": "invalid_grant",
"error_description": "AADSTS70002: Error validating credentials. AADSTS50155: Device is not authenticated.\\r\\nTrace ID: b099e7ad-ccf8-4eb7-b105-cced2f724d00\\r\\nCorrelation ID: 0d72010c-5a1f-4c19-99a7-48df28c5db66\\r\\nTimestamp: 2018-05-14 01:06:51Z",
"error_codes": [70002, 50155],
"trace_id": "b099e7ad-ccf8-4eb7-b105-cced2f724d00",
"correlation_id": "0d72010c-5a1f-4c19-99a7-48df28c5db66",
"suberror": "device_authentication_failed"
3.6 範例
3.6.1 要求
POST https://login.microsoftonline.com/425a8e89-feb9-40d2-9fe5-07fb45419e4b/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept-Charset: utf-8
Host: login.microsoftonline.com
Content-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sInJlc291cmNlIjoiaHR0cHM6Ly9taWNyb3NvZnQuY29tL21jcC1wcGUiLCJjbGllbnRfaWQiOiIxZWY0NjRlNS0wYjYxLTRjNmYtYjgyMi01ZGMwMTViOTQ2M2UiLCJyZWRpcmVjdF91cmkiOiJodHRwczovL21jcC1wcGUuYXp1cmV3ZWJzaXRlcy5uZXQvIiwiaXNzIjoiZTlhNjc1YTItYTdjNS00ZmU3LThlODMtZmUxZWZhZjgyZWM2In0.bmvBY7cdD\_dGtbB9dXbjbj5qc5k9ssqOMe1KQnnUnChLz1nkgBMLU\_jBMwsAoHCvI\_udQAdDgyNmWFcnWxTY0sLARZ6FQmjbGclqrqhj\_kkJXdkNBdGcwIXafjQiFkpDlpTMbVjBWoQq49aW-e\_OcmfsVIg8DCdS-s87x0fJ3fuHzZJzVGEHC4D-43EPxWTXfVbsvOV7RNK15lq5GXm10W4DkRngK6EpMq69g75KCUqT\_MEEh5dGezl5Kic8RLZQ72n5aEpc5Y6XK85b1TdOtBnxogVjJFSsxpz1sOIpODszVu9CSUg4CHEjadpKQ9DiYCg6zB9D5fYbMf3NrGWC9Q
3.6.2 回應
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Content-Length: 2473
"token_type":"Bearer",
"expires_in":"3599",
"ext_expires_in":"0",
"expires_on":"1525928144","not_before":"1525924244","resource":"<https://microsoft.com/mcp>",
"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImlCakwxUmNxemhpeTRmcHhJeGRacW9oTTJZayIsImtpZCI6ImlCakwxUmNxemhpeTRmcHhJeGRacW9oTTJZayJ9.eyJhdWQiOiJodHRwczovL21pY3Jvc29mdC5jb20vbWNwLXBwZSIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzQyNWE4ZTg5LWZlYjktNDBkMi05ZmU1LTA3ZmI0NTQxOWU0Yi8iLCJpYXQiOjE1MjU5MjQyNDQ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