2017-01-17 4 views
1

Ich versuche, eine native mobile App (Xamarin) mit Identity Server zu verbinden. Ich hatte ursprünglich den Fluss als implizit definiert und mir wurde gesagt, dass er inkorrekt sei. Daher habe ich den Autorisierungscodefluss geändert.Xamarin-Client mit Identity Server4 verbinden

Hier ist, wie mein Mandant Definition wie

sieht
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 
     } 

Und von meiner Xamarin App, das ist, wie ich auf die Identität Server verbinden.

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; 
    } 

ich das der Fehler "unauthorized_client" in der mobilen App, und in meinen Logs in Server zeigt:

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" 
    } 
    } 

Aber wenn Sie meinen Code überprüfen Ich habe keinen implict Fluss für dieser Clienttyp Und ich habe meine Datenbank doppelt überprüft, um sicherzustellen, dass es authorization_code ist. Ich schätze es, wenn mir jemand helfen könnte, das zu beheben.

+0

ich herausgefunden habe, ist der Fehler in der response, die ich von dem Client senden. Token ist für implizit, Code ist für Autorisierungscode-Fluss. Aber es gibt keinen Zugangscode zurück –

+0

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

Antwort

2

Es ist nicht so aussieht, obwohl idsrv4 code unterstützt, code token noch code id_token token als response_type im Moment - nur code id_token. Zumindest der aktuelle Demo-Site schlägt fehl, wenn Sie den Test-Client und eine /authorize Anfrage mit dem server.code Client versuchen.

Der einzige Arbeits Client ich mit einer Hybrid-Setup war im Zusammenhang mit Autorisierungscode gefunden (code id_token/server.hybrid):

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 

nicht sicher, warum das ist, wie es in der Liste der supported_response_types in der Entdeckung Dokument bereits ist . Dominic/Brock kann Vielleicht füllen

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

Nichtarbeits Code Fluss Auth Anfrage (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

Jetzt bekomme ich einen Fehler "client_id "fehlt oder zu lang. Aber ich habe definitiv die Anfrage bestätigt, und es hat die client_id "xamarin" drin –

+0

Wenn Sie versuchen, den Client mit Hybrid-Flow und verwenden Sie "Code ID_Token"? –

+0

Q2: Existiert der Scope: "api2" als Ressource in Ihren ApiResources? –

Verwandte Themen