Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure B2C ui_locales is directly supported via the auth request builder exception #237

Open
porojanmadalin opened this issue Aug 23, 2023 · 2 comments
Labels
android enhancement New feature or request

Comments

@porojanmadalin
Copy link

porojanmadalin commented Aug 23, 2023

Description

When I try to access the Azure B2C login page with a specific language for the ui_locales parameter, the application throws the following error and the Sign in/Sign up flow continues but the Sign in/Sign Up user flow language falls back to the default language (en).
This only happens on Android. I haven't tested on iOS yet but the web app works as expected.
I have not found any post regarding this issue. I have no idea on how I could even debug this.

java.lang.IllegalArgumentException: Parameter ui_locales is directly supported via the authorization request builder, use the builder method instead
                                                                                                    	at net.openid.appauth.Preconditions.checkArgument(Preconditions.java:132)
                                                                                                    	at net.openid.appauth.AdditionalParamsProcessor.checkAdditionalParams(AdditionalParamsProcessor.java:62)
                                                                                                    	at net.openid.appauth.AuthorizationRequest$Builder.setAdditionalParameters(AuthorizationRequest.java:957)
                                                                                                    	at com.byteowls.capacitor.oauth2.OAuth2ClientPlugin.authenticate(OAuth2ClientPlugin.java:268)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138)
                                                                                                    	at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:780)
                                                                                                    	at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0)
                                                                                                    	at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:942)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                    	at android.os.Looper.loop(Looper.java:288)
                                                                                                    	at android.os.HandlerThread.run(HandlerThread.java:67)

Capacitor version:

Run npx cap doctor:

   Capacitor Doctor   

Latest Dependencies:

  @capacitor/cli: 5.2.3
  @capacitor/core: 5.2.3
  @capacitor/android: 5.2.3
  @capacitor/ios: 5.2.3

Installed Dependencies:

  @capacitor/cli: 5.0.5
  @capacitor/core: 5.0.5
  @capacitor/android: 5.0.5
  @capacitor/ios: 5.0.5

[success] Android looking great! 👌
[error] Xcode is not installed

Library version:

  • 4.0.2

OAuth Provider:

  • Azure AD (B2C)

Your Plugin Configuration

{
  appId: ENVIRONMENT.auth.clientId,
  scope: `${ENVIRONMENT.auth.clientId} ${ENVIRONMENT.auth.scopes}`, 
  responseType: 'code',
  authorizationBaseUrl: ENVIRONMENT.auth.authBaseUrl,
  accessTokenEndpoint: ENVIRONMENT.auth.tokenEndpoint,
  additionalParameters: { ui_locales: currentAppLang, },
  web: {
    redirectUrl: ENVIRONMENT.auth.webRedirectUrl,
    additionalParameters: { ui_locales: currentAppLang, },
  },
  android: {
    pkceEnabled: true,
    redirectUrl: ENVIRONMENT.auth.androidRedirectUrl,
    handleResultOnActivityResult: true,
    handleResultOnNewIntent: true,
    additionalParameters: { ui_locales: currentAppLang, },
  },
  ios: {
    pkceEnabled: true, 
    redirectUrl: ENVIRONMENT.auth.iosRedirectUrl,
    additionalParameters: { ui_locales: currentAppLang, },
  },
}

Affected Platform(s):

  • Android

    • Version/API Level: 33
    • Device Model: Pixel 6 Pro
    • Content of your AndroidManifest.xml
    <?xml version='1.0' encoding='utf-8'?>
      <manifest package="com.my.app" xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true">
          <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/title_activity_main" android:launchMode="singleTask" android:name="com.my.app.MainActivity" android:theme="@style/AppTheme.NoActionBarLaunch">
              <intent-filter>
                  <action android:name="android.intent.action.MAIN" />
                  <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
              <intent-filter>
                  <action android:name="android.intent.action.VIEW" />
                  <category android:name="android.intent.category.DEFAULT" />
                  <category android:name="android.intent.category.BROWSABLE" />
                  <data android:host="oauth" android:scheme="@string/custom_url_scheme" />
              </intent-filter>
          </activity>
          <activity android:exported="true" android:name="net.openid.appauth.RedirectUriReceiverActivity">
              <intent-filter>
                  <action android:name="android.intent.action.VIEW" />
                  <category android:name="android.intent.category.DEFAULT" />
                  <category android:name="android.intent.category.BROWSABLE" />
                  <data android:host="oauth" android:scheme="@string/custom_url_scheme" />
              </intent-filter>
          </activity>
          <provider android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true" android:name="androidx.core.content.FileProvider">
              <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
          </provider>
      </application>
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
      <uses-feature android:name="android.hardware.location.gps" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.CAMERA" />
      <uses-permission android:name="android.permission.RECORD_AUDIO" />
      <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    </manifest>
    
@porojanmadalin porojanmadalin changed the title Azure B2C ui_locales is directly supported via the auth request builder error Azure B2C ui_locales is directly supported via the auth request builder exception Aug 23, 2023
@porojanmadalin
Copy link
Author

porojanmadalin commented Aug 23, 2023

I think it is an issue from the AppAuth Android sdk.
Changing the following lines fixed my problem, but these modifications do not persist on a new call of npm install
image

@porojanmadalin
Copy link
Author

porojanmadalin commented Aug 24, 2023

Solved by using the following workaround on Android:

if (additionalParams) {
    if (Capacitor.getPlatform() === PLATFORM.android) {
      if (UI_LOCALES in additionalParams) {
        config.authorizationBaseUrl = `${config.authorizationBaseUrl}?ui_locales=${additionalParams.ui_locales}&`;
      }
    } else {
      config.additionalParameters = additionalParams;
    }
  }

Note: the trailing & is necessary, otherwise it won't work for me

@moberwasserlechner moberwasserlechner added enhancement New feature or request android labels Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants