IdentityModel / IdentityModel.OidcClient.Samples

Apache License 2.0
296 stars 164 forks source link

An update to AndroidClientChromeCustomTabs with latest packages?? #14

Closed zahik closed 7 years ago

zahik commented 7 years ago

Can you please update the Android clients to work with the latest identitymodel.oidcClient packages? It isn't working right now (only with old version 1.1.0) Thanks.

leastprivilege commented 7 years ago

see #7

or please fix it and PR

zahik commented 7 years ago

Sorry, I'm new at this.... :)

jorgecotillo commented 7 years ago

I made the fix, is just simply upgrade the packages to v2, change the OidcClientOptions and instead of passing arguments to the constructor pass them as parameters and make sure to change the default response mode and set is a Redirect. I'll create a PR.

goonit commented 7 years ago

@jorgecotillo can you elaborate a little bit? What you stated has my app launching the custom tab to the redirect uri instead of the uri to identityserver's login.

jorgecotillo commented 7 years ago

@goonit that is a little strange unless you've changed the authority value. The fix is related to the default ResponseMode property value - from OidcClientOptions - that sets "POST" as the default value, which means that the token will be passed in the body when in fact what we need is to have the token to be appended to our RedirectUri.

goonit commented 7 years ago

@jorgecotillo I think I'm missing something else then. What should the redirectUri actually be for oidcClient in this scenario? In my scenario the request is coming from a xamarin.android mobile app, but I don't have an actual url to redirect back to, and the custom tab isn't automatically closing. Just 404's after logging into identity server since that url can't be found.

var options = new OidcClientOptions
                {
                    Authority = authority,
                    ClientId = "<clientid>",
                    ClientSecret = "<secret>",
                    Scope = "openid profile WellnessApp.WebAPI offline_access",
                    RedirectUri = "<android package name>://callback",
                    ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,
                    Browser = new ChromeCustomTabsWebView(this)
                };

I've also tried placing the idsrv 'signin-oidc' url in the redirectUri, but that seems to not change the end result.

goonit commented 7 years ago

Nevermind, I got it figured out. Didn't realize you are actually supposed to use the 'io.identitymodel.native://callback' as the redirect uri. I also wasn't requiring PKCE, so was getting an invalid_grant error when the uri was correctly set. All is well :)

jorgecotillo commented 7 years ago

Actually you can change the scheme (io.identitymodel.native) and the host (callback) you'll need to change it in CallbackInterceptorActivity.cs look at the attributes on top and you'll see DataScheme and DataHost. And yes, I recommend copying the IdentityServer client settings.