loonix / capacitor-oauth2-azure-example

Capacitor Oauth2 Azure B2C Example
6 stars 2 forks source link

Issues with redirectUrl for native application #1

Closed alfonsobravi closed 3 years ago

alfonsobravi commented 3 years ago

Hi,

I've successfully managed to configure the web version of this project to authenticate as expected to an Azure ADb2c tenant. Unfortunately, I am having issues with doing the same when running the project inside either Android or iOS. The issue looks similar on both platform: after opening the login form and go through the auth process, they both try to redirect back to http://localhost:4200/home which is (as expected) the redirect URI for the web section of the configuration. Can't really manage to debug the process more than that, given it's Azure service... But I've noticed quite a significant difference when it comes to redirection URI syntax between the capacitor-oauth2 (or this example) and what Azure control panel seems to suggest. I've obviously tried them both with no success. Any clues? Someone else been through the same issue? Thanks in advance.

loonix commented 3 years ago

You are having dificulties on the web, android or IOS? What are the configurations you have set?

From the text you sent it seems that you are able to get the redirect to work for web, because it redirects to the ..localhost:4200/home. For android or IOS you need to configure in azure like it is a native app. Then make sure you have the scopes added and the redirect URLS.

Regards,

alfonsobravi commented 3 years ago

Only Android and iOS. Here's my configuration, it's for a test environment, so feel free to give it a try. redirectUrl are in the format suggested by Azure, but I tried to replicate what it was on your example


appId: 'XXX',
authorizationBaseUrl:
'https://TENANT.b2clogin.com/TENANT.
onmicrosoft.com/B2C_1_signupsignin/oauth2/v2.0/authorize',
accessTokenEndpoint: '',
scope: 'openid offline_access',
responseType: 'id_token',
web: {
redirectUrl: 'http://localhost:4200/auth',
windowTarget: '_self'
},
android: {
pkceEnabled: true,
responseType: 'code',
redirectUrl: 'msauth://com.ORG.APP/2jmj7l5rSw0yVb%2FvlWAYkK%2FYBwk%3D',
accessTokenEndpoint:
'https://TENANT.b2clogin.com/TENANT.onmicrosoft.com/B2C_1_signupsignin',
handleResultOnNewIntent: true,
handleResultOnActivityResult: true
},
ios: {
pkceEnabled: true,
responseType: 'code',
redirectUrl: 'msauth.com.ORG.APP://auth',
accessTokenEndpoint:
'https://TENANT.b2clogin.com/TENANT.
onmicrosoft.com/B2C_1_signupsignin/oauth2/v2.0/token'
}
}; ```

On Mon, Aug 3, 2020 at 7:46 PM Daniel Carneiro <notifications@github.com>
wrote:

> You are having dificulties on the web, android or IOS?
> What are the configurations you have set?
>
> Regards,
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/loonix/capacitor-oauth2-azure-example/issues/1#issuecomment-667865383>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABF3DH2O6GWR7VUDMDGOR7DR6ZTOZANCNFSM4PS5GIQA>
> .
>
alfonsobravi commented 3 years ago

I've made some progress after switching to the legacy mode on the app configuration on Azure portal... I can now go through the process and return to the app, but I am now getting a JSON deserialization error:

E/Capacitor/Plugin: ERR_AUTHORIZATION_FAILED
    AuthorizationException: {"type":0,"code":5,"errorDescription":"JSON deserialization error"}

and, more in detail:

Caused by: org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject

which kinda points to a whole webpage content being parsed, clearly not some JSON stuff... That's on Android, btw.

On iOS it returns to the app, but with a (different) error:

[error] - OAuth rejected {"message":"ERR_NO_AUTHORIZATION_CODE","errorMessage":""}

Again, have you seen something similar happening, by any chance? ()

alfonsobravi commented 3 years ago

It was an issue on the Azure configuration side, unfortunately silently failing and throwing a 404. Legacy mode (on Azure) behaves better. Thanks for checking anyway.