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

Auth code is returnedby provider but error from plugin: Authorization failed on IOS - ERR_NO_AUTHORIZATION_CODE #279

Open
ap0894 opened this issue Oct 19, 2024 · 0 comments

Comments

@ap0894
Copy link

ap0894 commented Oct 19, 2024

Description

On platform iOS after user sucessfully completes login on OAUTH provider page user is redirected back to the app where the following is logged in XCode indicating that code parameter is correctly set in callback but plugin is erroring with ERR_NO_AUTHORIZATION_CODE

{"iosOpenInPlace":"","url":"com.refsix:\/\/oauth?code=kM1GbawNyK5xAU0m7SnpbIBy0RVWMatcR11_oxd3Ms4&state=LrRyMwj0TnbnjlobfIPI","iosSourceApplication":"com.apple.SafariViewService"}
I/Capacitor/GenericOAuth2Plugin: Authorization failed with The operation couldn’t be completed. (OAuthSwiftError error -11.)
ERROR MESSAGE:  {"message":"ERR_NO_AUTHORIZATION_CODE","errorMessage":"ERR_NO_AUTHORIZATION_CODE"}

Capacitor version:

Run npx cap doctor:

Latest Dependencies:

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

Installed Dependencies:

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

[info] Using Gemfile: RubyGems bundle installed
[success] iOS looking great! 👌
[success] Android looking great! 👌

Library version:

@capacitor-community/[email protected]

OAuth Provider:

Assignr. Documentation: https://assignr-api.readme.io/reference/authentication

Your Plugin Configuration

const startOAuthFlow = async () => {
        setLoading(true);
        try {
            console.log('Starting OAuth flow...');
            const result = await GenericOAuth2.authenticate({
                authorizationBaseUrl: 'https://api.assignr.com/oauth/authorize',
                accessTokenEndpoint: 'https://api.assignr.com/oauth/token',
                appId: CLIENT_ID,
                scope: 'games.read account.read',
                resourceUrl: '',
                logsEnabled: true,
                web: {
                    appId: CLIENT_ID,
                    responseType: "code",
                    accessTokenEndpoint: "https://api.assignr.com/oauth/token",
                    redirectUrl: REDIRECT_URI_WEB,
                    windowOptions: "height=600,left=0,top=0"
                },
                android: {
                    appId: CLIENT_ID,
                    responseType: "code",
                    pkceEnabled: true,
                    redirectUrl: REDIRECT_URI_ANDROID
                },
                ios: {
                    appId: CLIENT_ID,
                    responseType: "code",
                    pkceEnabled: true,
                    redirectUrl: REDIRECT_URI_IOS
                }
            });

            console.log('Authorization Code: ', result.authorizationCode);
            window.dispatchEvent(new CustomEvent('AuthorizationCodeReceived', { detail: result.authorizationCode }));
            setLoading(false);
        } catch (error: any) {
            console.error('OAuth2 Error:', JSON.stringify(error, null, 2));
            if (error.message === 'USER_CANCELLED') {
                console.log('User cancelled the authentication process.');
            } else {
                console.error('Error Details:', error);
            }
            setLoading(false);
        }
    };

Affected Platform(s):

  • iOS

    • Version/API Level: iOS 17.5 (21F79)
    • Device Model: iPhone 15 Pro
    • Content of your Info.plist
      <key>CFBundleURLTypes</key>
      <array>
      	<dict>
      		<key>CFBundleURLName</key>
      		<string>com.refsix</string>
      		<key>CFBundleURLSchemes</key>
      		<array>
      			<string>com.refsix</string>
      			<string>com.googleusercontent.apps.725565408878-gm2oam4oaje6h9noedv513e0ac6vigrb</string>
      		</array>
      	</dict>
      </array>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant