-
Notifications
You must be signed in to change notification settings - Fork 260
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
fetchAuthSession() throws SignedOutException #5896
Comments
Future<String?> restoreSession() async {
final session = await Amplify.Auth.fetchAuthSession(
options: const FetchAuthSessionOptions(
forceRefresh: true,
),
);
if (session.isSignedIn) {
final user = await Amplify.Auth.getCurrentUser();
return user.username;
}
return null;
} Observations:
|
Related to #441 |
Hello @Alvish0407, thank you for taking the time to provide all of these details. We will attempt to reproduce the issue with your token expiration configuration and get back to you with our findings. |
Hi @Alvish0407, I used the same token expirations as you described but have been unsuccessful in reproducing it, fethcing the auth session every 5 minutes for an hour, everything seemed to work fine. You marked that you deployed with the cdk, can you provide details on how exactly you configured amplify and provide your outputs/ config file with anything secret removed? |
Thank you for your prompt response, @ekjotmultani. I appreciate it. Here’s the frontend configuration. switch (appFlavor) {
case Flavor.prod:
authenticationFlowType = 'USER_PASSWORD_AUTH';
region = 'us-east-2';
poolId = '${region}(hidden)';
appClientId = '(hidden)';
break;
case Flavor.dev:
authenticationFlowType = 'USER_SRP_AUTH';
region = 'ca-central-1';
poolId = '${region}(hidden)';
appClientId = '(hidden)';
break;
default:
authenticationFlowType = '';
poolId = '';
appClientId = '';
region = '';
} {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"auth": {
"plugins": {
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CognitoUserPool": {
"Default": {
"PoolId": "$poolId",
"AppClientId": "$appClientId",
"Region": "$region"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "$authenticationFlowType"
}
},
"PinpointAnalytics": {
"Default": {
"AppId": "(hidden)",
"Region": "us-east-1"
}
},
"PinpointTargeting": {
"Default": {
"Region": "us-east-1"
}
}
}
}
},
"analytics": {
"plugins": {
"awsPinpointAnalyticsPlugin": {
"pinpointAnalytics": {
"appId": "(hidden)",
"region": "us-east-1"
},
"pinpointTargeting": {
"region": "us-east-1"
}
}
}
},
"api": {
"plugins": {
"awsAPIPlugin": {
"towtaledbackendgraph": {
"endpointType": "GraphQL",
"endpoint": "(hidden)",
"region": "ca-central-1",
"authorizationType": "API_KEY",
"apiKey": "(hidden)"
}
}
}
}
} |
Hello @Alvish0407, I've been unable to reproduce the issue as well. I modified my Configuration file to match your Auth definitions as closely as possible, but I'm still not having any luck. As a side note you seem to have duplicate PinpointAnalytics and PinpointTargeting fields defined within your configuration. Could you please help us with the following:
|
@tyllark Thank you for your response.
createCognitoUserPool(): cognito.IUserPool {
if (APP_ENV_CONSTANTS.APP_ENV === 'dev') {
return cognito.UserPool.fromUserPoolId(this, 'ExistingUserPool', APP_ENV_CONSTANTS.COGNITO_USER_POOL_ID);
}
const userMigrationLambda = this.createServiceLambda("UserMigrationLambda", {
code: lambda.Code.fromAsset('src/cognito-auth/'),
role: this.towtaledServiceLambdaRole,
environment: {
OLD_COGNITO_USER_POOL_ID: APP_ENV_CONSTANTS.OLD_COGNITO_USER_POOL_ID,
OLD_COGNITO_REGION: APP_ENV_CONSTANTS.OLD_COGNITO_REGION,
OLD_MOBILE_APP_CLIENT_ID: APP_ENV_CONSTANTS.OLD_MOBILE_APP_CLIENT_ID,
},
handler: 'user-migration.handler'
})
return new cognito.UserPool(this, `${APP_ENV_CONSTANTS.APP_PREFIX}-UserPool`, {
userPoolName: `${APP_ENV_CONSTANTS.APP_PREFIX}-UserPool`,
selfSignUpEnabled: true,
autoVerify: { email: true },
accountRecovery: cognito.AccountRecovery.PHONE_AND_EMAIL,
userVerification: {
emailStyle: cognito.VerificationEmailStyle.CODE,
},
lambdaTriggers: {
userMigration: userMigrationLambda,
},
customAttributes: {
'subscriptionStatus': new cognito.StringAttribute({ mutable: true }),
'revenueCatID': new cognito.StringAttribute({ mutable: true }),
},
passwordPolicy: {
requireLowercase: false,
requireUppercase: false,
requireDigits: false,
requireSymbols: false,
}
});
}
createCognitoUserPoolClient(userPool: cognito.IUserPool): cognito.IUserPoolClient {
if(APP_ENV_CONSTANTS.APP_ENV == "dev") {
return cognito.UserPoolClient.fromUserPoolClientId(this, 'ExistingUserPoolClient', APP_ENV_CONSTANTS.MOBILE_APP_CLIENT_ID);
}
return userPool.addClient('MobileAppClient', {
userPoolClientName: `${APP_ENV_CONSTANTS.APP_PREFIX}-MobileAppClient`,
authFlows: {
adminUserPassword: true,
userPassword: true,
userSrp: true,
custom: true
},
accessTokenValidity: cdk.Duration.days(1),
idTokenValidity: cdk.Duration.days(1),
refreshTokenValidity: cdk.Duration.days(30),
});
}
|
Earlier, we encountered an issue only with the One thing I’ve noticed is that the token gets refreshed once, and after that, it throws a |
I attempted to reproduce the issue using the provided snippet, but I was unable to generate the problem. Even after modifying the snippet to align with my project’s configuration and following the steps that enable me to create the issue in my project, it remained unsuccessful. I noticed an instance where the token continues to refresh immediately after the user logs in and persists within the same application session. As soon as I execute a hot restart, the token refreshes a maximum of once, and it subsequently throws a |
@ekjotmultani @tyllark What are some possible causes that could be throwing a |
@Alvish0407 Initially I thought the multiple backends or your Authentication flows (ALLOW_REFRESH_TOKEN_AUTH) could be the cause of the issue, but that was ruled out by your ability to get at least 1 successful refresh. Another consideration was if you had enabled token revocation, but that shouldn't be trigger by just a hot restart. My current hunch is that we have a bug in our native layers where we "reconfigure/setup" during a hot restart. We had an issue related to hot restart earlier, where we had stale references to objects after a hot restart. I haven't had a chance to reproduce the issue with the cdk script you provided yet, but I will provide an update here once I do. |
@tyllark Hello, It says "Refresh Token has been revoked" ![]() |
Btw, I'm using final result = await Amplify.Auth.signIn(
password: password,
username: email.toLowerCase(),
options: const SignInOptions(
pluginOptions: CognitoSignInPluginOptions(
authFlowType: AuthenticationFlowType.userPasswordAuth,
),
),
); |
@tyllark @ekjotmultani any luck? |
Seems related #2260 |
Description
Expiration Duration:
The idToken and accessToken refresh successfully only once. After that, the user is logged out instead of the tokens continuing to renew as expected.
Error Details:
Related Discussion:
Previous conversation on GitHub
Categories
Steps to Reproduce
Steps to Reproduce:
Configure Token Expiration Durations:
Log in using email and password.
Wait for 10-15 minutes to allow token expiration and renewal attempts.
Fetch the user session using:
Observe the error mentioned above, indicating that the user is logged out instead of the tokens being refreshed.
Screenshots
No response
Platforms
Flutter Version
3.24.1
Amplify Flutter Version
^2.3.0
Deployment Method
AWS CDK
Schema
The text was updated successfully, but these errors were encountered: