Skip to content

Azure B2C - redirect uri provided in the request is not registered for the client id #96

@loonix

Description

@loonix

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

  1. Open emulator with app
  2. Click Login
  3. Accesses the login page (azure)
  4. Automatically returns to the app
  5. 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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions