capacitor-oauth2: Azure B2C - redirect uri provided in the request is not registered for the client id
Description
Hi guys, I am able to login using the web configs but when I try to login on android it seems that it is not working for me, would be great if someone can give me some help with this.
Steps
- Open emulator with app
- Click Login
- Accesses the login page (azure)
- Automatically returns to the app
- Throws an error
Chrome Inspector:
main.js:1265 OAuth rejected Error: ERR_GENERAL
at Object.fromNative (capacitor-runtime.js:226)
at <anonymous>:1:18
Android Studio:
2020-05-14 11:48:31.958 26720-26720/com.cads.testapp E/Capacitor/Plugin: ERR_GENERAL
AuthorizationException: {"type":1,"code":1008,"error":"redirect_uri_mismatch","errorDescription":"AADB2C90006: The redirect URI 'com.cads.testapp:\/\/oauth\/redirect' provided in the request is not registered for the client id 'XXXXXXXX-XXXXXXX-XXXXXXX'.\r\nCorrelation ID: XXXXX-XXXXXX-XXXXXX\r\nTimestamp: 2020-05-14 10:48:30Z\r\n"}
at com.byteowls.capacitor.oauth2.OAuth2ClientPlugin.handleAuthorizationRequestActivity(OAuth2ClientPlugin.java:333)
at com.byteowls.capacitor.oauth2.OAuth2ClientPlugin.handleOnActivityResult(OAuth2ClientPlugin.java:321)
at com.getcapacitor.Bridge.onActivityResult(Bridge.java:770)
at com.getcapacitor.BridgeActivity.onActivityResult(BridgeActivity.java:212)
at android.app.Activity.dispatchActivityResult(Activity.java:7454)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4353)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4402)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2020-05-14 11:48:31.971 26720-26720/com.cads.smartanchortest E/Capacitor/Console: File: http://localhost/main.js - Line 1265 - Msg: OAuth rejected
Capacitor version: 2.1.0
Capacitor Doctor
Latest Dependencies:
@capacitor/cli: 2.1.0
@capacitor/core: 2.1.0
@capacitor/android: 2.1.0
@capacitor/electron: 2.1.0
@capacitor/ios: 2.1.0
Installed Dependencies:
@capacitor/electron not installed
@capacitor/cli 2.0.0
@capacitor/ios 2.0.0
@capacitor/core 2.0.0
@capacitor/android 2.0.0
[success] Android looking great! �
Library version: 2.0.0
OAuth Provider: Azure B2C
Your Plugin Configuration
{
appId: 'XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXX,
authorizationBaseUrl: 'https://TENANT.b2clogin.com/tfp/TENANT.onmicrosoft.com/B2C_1_policy-signin-signup-web/oauth2/v2.0/authorize',
accessTokenEndpoint: '',
scope: 'https://XXXXXXX.onmicrosoft.com/TestApi4/demo.read',
responseType: 'token',
web: {
redirectUrl: 'http://localhost:8100/'
},
android: {
pkceEnabled: true,
responseType: 'code',
redirectUrl: 'com.cads.testapp://oauth/redirect',
accessTokenEndpoint: 'https://TENANT.b2clogin.com/TENANT.onmicrosoft.com/B2C_1_policy-signin-signup-web',
handleResultOnNewIntent: true,
handleResultOnActivityResult: true
},
ios: {
pkceEnabled: true,
responseType: 'code',
redirectUrl: 'com.cads.testapp://oauth',
accessTokenEndpoint: 'https://TENANT.b2clogin.com/TENANT.onmicrosoft.com/B2C_1_policy-signin-signup-web',
}
}
Notes:
I have checked the azure settings and I have configured the Custom Redirect URI to com.cads.testapp://oauth/redirect but still am facing this issue.
If I change the following:
{
...
handleResultOnNewIntent: true,
handleResultOnActivityResult: false
...
}
It opens the login page and redirects to the app but does not give any error, but it does not pass any parameter either
EDIT:
it seems that the redirect URI add a backslash before :
The redirect URI 'com.cads.testapp:\/\/oauth\/redirect' provided in the request is not registered for the client id
Has anyone came across this issue, or knows a way to fix this? Many thanks for the awesome plugin!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (9 by maintainers)
Links to this issue
Commits related to this issue
- docs(): Add another b2c example #96 — committed to moberwasserlechner/capacitor-oauth2 by moberwasserlechner 4 years ago
But could you plz open a new issue in case of a iOS problem. With all the discussion in this one it is would be hard to keep track of the new problem. thx
The current logout function is not what you expect. It simply cleans any cached tokens but does not log you out of the provider. For that to work you would have to provide a logout url, which is not supported (yet).
But you can create a new feature request task and I try to include that in one of the upcoming releases, but I can’t give you a timeline.
@loonix Thx for the answer and for the repo.
I linked it here and copied your config as another example for azure b2c.
PS: My comment was not meant to be offending in any kind. Your questions helped to make the docs more helpful, especially for devs, that are new to Capacitor and OAuth. PSS: I keep this task open until you finish the iOS part and if you have questions please ask.
@loonix I’m glad you solved your config issue.
Don’t get me wrong but I try to prevent such tasks with documentation in the README. So just one final question:
There was no bug in the plugin or in the documentation. If you had followed the Android section in the README and did not had the typo in your config everything would be fine?
https://docs.microsoft.com/en-us/azure/active-directory-b2c/tutorial-register-applications?tabs=applications