flutter_appauth icon indicating copy to clipboard operation
flutter_appauth copied to clipboard

token_failed, Failed to get token

Open itskgore opened this issue 1 year ago • 5 comments

I'm getting the following error after 3 attempts of a successful token refresh method calls in the 4th attempt I'm getting the following error:

PlatformException(token_failed, Failed to get token: invalid_grant: The refresh token is invalid or expired., null, null)

I'm using OKTA for OAuth.

This is my method:

final oktaRefresh = await appAuth.token(TokenRequest(
            '${Repository.env!['OKTACLIENTID']}',
            '${Repository.env!['OKTAREDIRECTURL']}',
            discoveryUrl:
                'https://${Repository.env!['OKTADOMAIN']}/oauth2/${Repository.env!['OKTAUTHORIZER']}/.well-known/openid-configuration',
            refreshToken: refreshToken,
            grantType: "refresh_token",
            scopes: ["openid", "profile", "offline_access"]));

itskgore avatar Feb 20 '24 15:02 itskgore

I am encountering the same issue and am unable to determine whether it originates from the Okta console or the app itself

d2square avatar Feb 20 '24 15:02 d2square

I'm getting the following error after 3 attempts of a successful token refresh method calls in the 4th attempt I'm getting the following error:

PlatformException(token_failed, Failed to get token: invalid_grant: The refresh token is invalid or expired., null, null)

I'm using OKTA for OAuth.

This is my method:

final oktaRefresh = await appAuth.token(TokenRequest(
            '${Repository.env!['OKTACLIENTID']}',
            '${Repository.env!['OKTAREDIRECTURL']}',
            discoveryUrl:
                'https://${Repository.env!['OKTADOMAIN']}/oauth2/${Repository.env!['OKTAUTHORIZER']}/.well-known/openid-configuration',
            refreshToken: refreshToken,
            grantType: "refresh_token",
            scopes: ["openid", "profile", "offline_access"]));

Are you seeing this on Android only or iOS and Android, noticed today the 1st token refresh on Android in a B2C flow is throwing this error and the 2nd attempt works but on iOS it works fine

mackayn avatar Feb 22 '24 10:02 mackayn

@MaikuB I've tried this but no luck, Also, this is coming for iOS for 3rd time only the first 2 times it works fine.

itskgore avatar Feb 22 '24 11:02 itskgore

Facing same issue. Any progress?

shaz-tech avatar Mar 13 '24 16:03 shaz-tech

Hello, I had this problem, (I use a Keycloak) my refresh tokens works 2-3 times but never more. So I migrated to this package oidc and I still had the problem. I solved it by adding offline_access to the scopes.

(I find OIDC easier to use, it automatically handles token refreshes and has a basic implementation for FlutterSecureStorage).

Hopefully this helps someone.

ThomasBernard03 avatar Nov 14 '24 12:11 ThomasBernard03