2017-01-17 3 views
1

ネイティブモバイルアプリケーション(xamarin)をIdentity Serverに接続しようとしています。私は最初に流れを暗黙的に設定していましたが、私はその流れが間違っていると言いました。それで私はそれを認証コードフローに変更しました。私のクライアントの定義はXamarinクライアントをIdentity Server4に接続する

new Client 
    { 
     ClientId = "Xamarin", 
     ClientName = "Xamarin Client", 
     AllowedGrantTypes = GrantTypes.Code, 
     AllowAccessTokensViaBrowser = true, 
     RedirectUris = { "http://xx.xx.xx.xx/signin-oidc" }, 
     PostLogoutRedirectUris = { "http://xx.xx.xx.xx/signin-oidc" }, 
     AllowedCorsOrigins = { "http://xx.xx.xx.xx" }, 
     AllowedScopes = 
      { 
       StandardScopes.OpenId.Name, 
       StandardScopes.Profile.Name, 
       "api1" 
      }, 
     RequireConsent = false 
     } 

好きで、私のxamarinアプリからどのように見えるかをここで

があり、これは私がアイデンティティサーバーに接続する方法です。

void LoginButton_Clicked(object sender, EventArgs e) 
    { 
     StartFlow("token", "api1"); 
    } 

    public void StartFlow(string responseType, string scope) 
    { 
     var authorizeRequest = 
      new AuthorizeRequest("http://xx.xx.xx.xx/connect/authorize"); 


     var dic = new Dictionary<string, string>(); 
     dic.Add("client_id", "Xamarin"); 
     dic.Add("response_type", responseType); 
     dic.Add("scope", scope); 
     dic.Add("redirect_uri", "http://xx.xx.xx.xx/signin-oidc"); 
     dic.Add("nonce", Guid.NewGuid().ToString("N")); 


     _currentCSRFToken = Guid.NewGuid().ToString("N"); 
     dic.Add("state", _currentCSRFToken); 

     var authorizeUri = authorizeRequest.Create(dic); 
     webLogin.Source = authorizeUri; 
     webLogin.IsVisible = true; 
    } 

私は、モバイルアプリでのエラー「unauthorized_client」を取得し、サーバの私のログに示しています

fail: IdentityServer4.Validation.AuthorizeRequestValidator[0] 
    Invalid grant type for client: implicit 
    { 
    "ClientId": "Xamarin", 
    "ClientName": "Xamarin Client", 
    "RedirectUri": "http://xx.xx.xx.xx/signin-oidc", 
    "AllowedRedirectUris": [ 
     "http://xx.xx.xx.xx/signin-oidc" 
    ], 
    "SubjectId": "anonymous", 
    "ResponseType": "token", 
    "ResponseMode": "fragment", 
    "GrantType": "implicit", 
    "RequestedScopes": "", 
    "State": "5c53c5e5bbe44c0f8c5d4b401df0938e", 
    "Raw": { 
     "client_id": "Xamarin", 
     "response_type": "token", 
     "scope": "api1", 
     "redirect_uri": "http://xx.xx.xx.xx/signin-oidc", 
     "nonce": "49f21e8873d744bea76f6f00ebae3eb4", 
     "state": "5c53c5e5bbe44c0f8c5d4b401df0938e" 
    } 
    } 
    fail: IdentityServer4.Endpoints.AuthorizeEndpoint[0] 
    Request validation failed 
    info: IdentityServer4.Endpoints.AuthorizeEndpoint[0] 
    { 
    "ClientId": "Xamarin", 
    "ClientName": "Xamarin Client", 
    "RedirectUri": "http://xx.xx.xx.xx/signin-oidc", 
    "AllowedRedirectUris": [ 
     "http://xx.xx.xx.xx/signin-oidc" 
    ], 
    "SubjectId": "anonymous", 
    "ResponseType": "token", 
    "ResponseMode": "fragment", 
    "GrantType": "implicit", 
    "RequestedScopes": "", 
    "State": "5c53c5e5bbe44c0f8c5d4b401df0938e", 
    "Raw": { 
     "client_id": "Xamarin", 
     "response_type": "token", 
     "scope": "api1", 
     "redirect_uri": "http://xx.xx.xx.xx/signin-oidc", 
     "nonce": "49f21e8873d744bea76f6f00ebae3eb4", 
     "state": "5c53c5e5bbe44c0f8c5d4b401df0938e" 
    } 
    } 

しかし、あなたは私のコードをチェックすると、私はのためのimplictの流れを持っていませんこのクライアントタイプ。そして私はそれがauthorization_codeであることを確認するためにデータベースを二重にチェックしました。私は誰かがこれを修正するのを助けることができれば感謝します。

+0

を私はエラーが私がクライアントから送信responsetypeである考え出しました。トークンは暗黙のためのものであり、コードは認証コードの流れのためのものである。しかし、それはアクセスコードを返しません –

+0

https://leastprivilege.com/2016/01/17/which-openid-connectoauth-2-o-flow-is-the-right-one/ –

答えて

2

idsrv4がresponse_typeとしてcodecode tokencode id_token tokenをサポートしているかのようにそれは現時点では見ていません - だけcode id_token。テストクライアントを試すときには少なくとも現在のデモサイトが失敗し、server.codeクライアントを使用して/authorizeリクエストが失敗します。それが発見文書にsupported_response_typesのリストにすでにだとしてそれは、ある理由

https://demo.identityserver.io/connect/authorize? 
    client_id=server.hybrid& 
    response_type=code id_token& 
    response_mode=fragment& 
    redirect_uri=https://notused& 
    scope=openid api& 
    state=1& 
    nonce=2 

わからない:私は認証コードに関連した

ザ・唯一の作業クライアントは、ハイブリッドのセットアップ(code id_token/server.hybrid)としました。多分ドミニク/ Brockさんは埋めることができ

"response_types_supported": [ 
    "code", 
    "token", 
    "id_token", 
    "id_token token", 
    "code id_token", 
    "code token", 
    "code id_token token" 
    ], 

ノンワーキングコードフローの認証要求(unsupported_response_type):。

https://demo.identityserver.io/connect/authorize? 
    client_id=server.code& 
    response_type=code& 
    response_mode=fragment& 
    redirect_uri=https://notused& 
    scope=openid api& 
    state=1& 
    nonce=2 
+0

今私はエラー "client_id "が不足しているか、長すぎます。しかし、私は間違いなく要求を確認しており、クライアントIDは "xamarin"になっています –

+0

クライアントをハイブリッドフローに設定して "code id_token"を使用しようとすると、 –

+0

Q2:ApiResourcesに "api2"というスコープがリソースとして存在しますか? –

関連する問題