capacitor-community / generic-oauth2

Generic Capacitor OAuth 2 client plugin. Stop the war in Ukraine!
MIT License
223 stars 106 forks source link

Is authorization_code only flow possible? (ERR_NO_AUTHORIZATION_CODE) #199

Open fangornoftheforest opened 2 years ago

fangornoftheforest commented 2 years ago

Flow type: Authorization code Platform: iOS Provider: Azure Error: ERR_NO_AUTHORIZATION_CODE

Code:

            const options = {
                authorizationBaseUrl: 'https://login.microsoftonline.com/tenantid/oauth2/v2.0/authorize',
                accessTokenEndpoint: null, (<- documentation leaves me unsure if I need to set this to null, blank or absent)
                resourceUrl: null,
                scope: 'api://foo/foo.Read openid offline_access email'
                logsEnabled: true,
                pkceEnabled: true,
                ios: {
                    appId: foo
                    responseType: "code",
                    redirectUrl: msauth.foo.bar://auth
                }
            }

Plugin returns ERR_NO_AUTHORIZATION_CODE even though the authorization code is present in the response parameters at OAuth2Swift:127.

The flow I am using is to fetch the authorization code and pass this to our back-end to resolve the refresh and ID token. This works without issue on Android but seems to be a huge problem on iOS. I have tried to ignore the response and parse the redirect using appUrlOpen but there seems to be no way to access the codeVerifier. Any advice?

phanireddy18 commented 1 year ago

Even we face the same issue in iOS. Is it possible to send only code to the front end without trying to get an access token? I was able to make it work by commenting our code in the block starting at line 127 and writing "completion(.success((this.client.credential, nil, responseParameters)))" and ByteowlsCapacitorOauth2.swift - line, commenting out else block and just writing "call.resolve(parameters)" worked for me. OAuth2Client.authenticate(), I had to put additional conditions to check if "code" existed in response, but maybe you can write code to make it consistent with android.