okta / okta-auth-js

The official js wrapper around Okta's auth API
Other
454 stars 265 forks source link

In Okta login API flow, getting "Auth API Error when we connect with iOS device #670

Open muthurajan2021 opened 3 years ago

muthurajan2021 commented 3 years ago

I have followed the below tutorial to login okta. it works fine in browser with localhost. When we connect with iOS device, its doesn't allow to login and getting the error "AuthAPIError".

Run Command : ionic serve iOS Command: ionic cordova build ios Refereed link: https://developer.okta.com/blog/2017/08/22/build-an-ionic-app-with-user-authentication

Source Code. this.oauthService.createAndSaveNonce().then(nonce => { const authClient = new OktaAuth( { clientId: this.oauthService.clientId, pkce: true, redirectUri: this.oauthService.redirectUri, issuer: OKTA_ISSUER }); return authClient.signInWithCredentials({ username: this.username, password: this.password }).then((response) => { console.log('Sign in Response =',response); if (response.status === 'SUCCESS') {

      return authClient.token.getWithoutPrompt({
        nonce: nonce,
        responseType: ['id_token', 'token'],
        sessionToken: response.sessionToken,
        scopes: this.oauthService.scope.split(' ')
      })
        .then((tokens) => {
          const idToken = tokens.tokens.idToken;    //tokens[0].idToken;
          const accessToken = tokens.tokens.accessToken;
          console.log('Okta access token =',accessToken);
 }

Please help me to resolve the issue.

oleksandrpravosudko-okta commented 3 years ago

Thanks for reaching out @muthurajan2021.

Linked blogpost looks a bit dated - it is likely that it is not compatible with the latest(i.e. npm install @okta/okta-auth-js) auth-js SDK.

Did you have a chance to go through its updated version? It seems to be running w/o errors on the iOS sim.

muthurajan2021 commented 3 years ago

Thanks for your prompt replied. I have already tried this which you have shared. Our mobile application is ionic angular cordova. I have integrated okta login with okta schematics. It works fine on ionic 4.0 and above.

Referred Link : https://developer.okta.com/blog/2019/06/20/ionic-4-tutorial-user-authentication-and-registration

We have an existing ionic mobile application with ionic version 3.9.9. How can we integrate okta schematics flow without upgrade ionic 4.0 version ?

mraible commented 3 years ago

The first release of OktaDev Schematics that supported Ionic only supported Ionic 4.

https://github.com/oktadeveloper/schematics/releases/tag/v0.7.0

You could try integrating Ionic AppAuth yourself. OktaDev Schematics just automates the process.

https://github.com/wi3land/ionic-appauth

On Mar 25, 2021, at 07:58, muthurajan2021 @.***> wrote:

 Thanks for your prompt replied. I have already tried this which you have shared. Our mobile application is ionic angular cordova. I have integrated okta login with okta schematics. It works fine on ionic 4.0 and above.

Referred Link : https://developer.okta.com/blog/2019/06/20/ionic-4-tutorial-user-authentication-and-registration

We have an existing ionic mobile application with ionic version 3.9.9. How can we integrate okta schematics flow without upgrade ionic 4.0 version ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

muthurajan2021 commented 3 years ago

Thanks Matt. I will try the Ionic AppAuth github link and let you know if i have any doubts.

muthurajan2021 commented 3 years ago

Hi Matt - I have tried below Github link which you have shared. This is also not working because of it also developed ionic angular version 5.4.3. when we tried to implement Okta files manually, we are getting more kind of build errors due to ionic-angular version.

https://github.com/wi3land/ionic-appauth

Could you please provide any documents / Github ulr to implement okta login without upgrade ionic 4 and above version ?

mraible commented 3 years ago

@muthurajan2021 The original blog post you linked to seems to use Ionic Angular 3.9.2. If you use the same version numbers for dependencies in your app, it might work. https://github.com/oktadeveloper/okta-ionic-auth-example

muthurajan2021 commented 3 years ago

Thanks Matt. I have tried with same ionic angular version 3.9.2 in OKTA API flow. it logged in successfully but it throws below error to get access token when we connect with iOS device.

Error {name: "AuthSdkError", message: "OAuth flow timed out", errorCode: "INTERNAL", errorSummary: "OAuth flow timed out", errorLink: "INTERNAL", …}.

Note : I have added custom url scheme in pacakage.json file. "cordova-plugin-customurlscheme": { "URL_SCHEME": "com.okta.dev-2261331" }

Please help me to resolve this error issue.

mraible commented 3 years ago

Do you have Implicit Flow enabled in your Okta OIDC app?

On Mar 30, 2021, at 05:19, muthurajan2021 @.***> wrote:

 Thanks Matt. I have tried with same ionic angular version 3.9.2 in OKTA API flow. it logged in successfully but it throws below error to get access token when we connect with iOS device.

Error {name: "AuthSdkError", message: "OAuth flow timed out", errorCode: "INTERNAL", errorSummary: "OAuth flow timed out", errorLink: "INTERNAL", …}.

Note : I have added custom url scheme in pacakage.json file. "cordova-plugin-customurlscheme": { "URL_SCHEME": "com.okta.dev-2261331" }

Please help me to resolve this error issue.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.