Asp.net-Identity
卡在 Azure OAuth2 令牌請求中的兩個錯誤之間
我正在為 OWIN 和 Azure Active Director 實施 OAuth2 提供程序。FWIW,此時 OpenId Connect 選項不符合這項工作的要求。
我得到一個授權碼,並返回我的回复 url 和 auth_code,狀態,並請求令牌到“scheme://login.windows.net/{myguid}/oauth2/token.
// Build up the body for the token request var body = new List<KeyValuePair<string, string>>(); body.Add(new KeyValuePair<string, string>("grant_type", "authorization_code")); body.Add(new KeyValuePair<string, string>("code", code)); body.Add(new KeyValuePair<string, string>("redirect_uri", redirectUri)); body.Add(new KeyValuePair<string, string>("client_id", Options.ClientId)); body.Add(new KeyValuePair<string, string>("client_secret", Options.ClientSecret)); // Request the token HttpResponseMessage tokenResponse = await httpClient.PostAsync(TokenEndpoint, new FormUrlEncodedContent(body)); string text = await tokenResponse.Content.ReadAsStringAsync(); tokenResponse.EnsureSuccessStatusCode();我收到此錯誤:
{"error":"invalid_resource","error_description":"AADSTS50001: Resource identifier is not provided. Trace ID: 227f2af8-0837-4f22-ac0f-a09b3f9a6d50 Correlation ID: 3d783f11-44d0-4efa-8831-3dd581d653ed Timestamp: 2014-08-08 21:59:49Z","error_codes":[50001],"timestamp":"2014-08-08 21:59:49Z","trace_id":"227f2af8-0837-4f22-ac0f-a09b3f9a6d50","correlation_id":"3d783f11-44d0-4efa-8831-3dd581d653ed"}好的,我添加資源選項:
// Build up the body for the token request var body = new List<KeyValuePair<string, string>>(); body.Add(new KeyValuePair<string, string>("grant_type", "authorization_code")); body.Add(new KeyValuePair<string, string>("code", code)); body.Add(new KeyValuePair<string, string>("redirect_uri", redirectUri)); body.Add(new KeyValuePair<string, string>("client_id", Options.ClientId)); body.Add(new KeyValuePair<string, string>("client_secret", Options.ClientSecret)); body.Add(new KeyValuePair<string, string>("resource", "https://myappid")); {"error":"invalid_request","error_description":"AADSTS90027: The client 'xxxxx' and resource 'https://myappid' identify the same application. Trace ID: 6c77f123-d75f-43a9-8117-b3f372891ee4 Correlation ID: d9081f8b-b690-4478-bf15-55325a9736ec Timestamp: 2014-08-08 21:48:34Z","error_codes":[90027],"timestamp":"2014-08-08 21:48:34Z","trace_id":"6c77f123-d75f-43a9-8117-b3f372891ee4","correlation_id":"d9081f8b-b690-4478-bf15-55325a9736ec"}所以我必須擁有與我的客戶 ID 相關聯的正確應用 ID。哼!我顯然做錯了什麼,但似乎看不到它。有什麼建議麼?
我有同樣的問題,我只是想實現一個使用者登錄。
在嘗試了 1000 件事情(其中包括這篇文章)後,我發現我可以使用 Microsoft.Azure.ActiveDirectory-id 作為資源參數。這樣我就不必創建第二個應用程序。
nameValuePairs.add(new BasicNameValuePair("resource", "00000002-0000-0000-c000-000000000000"));並得到了令牌
更新:
天藍色的支持建議我使用**https://graph.windows.net/**:
nameValuePairs.add(new BasicNameValuePair("resource", "https://graph.windows.net/"));
在授權請求中使用“openid”範圍應該會觸發一個 OpenID Connect 流,該流將返回一個 id_token 並且不需要資源。