Closed saswat-pcode closed 2 years ago
Hello @saswat-pcode - let me know if this doesn't answer your question - https://docs.amplify.aws/lib/auth/access_credentials/q/platform/flutter/
Thank you @Jordan-Nelson .
@Jordan-Nelson for me it doesn’t work, because what I need is an authorisation key to send in the headers when I do the api call(outside of Amplify) and the example in the documentation doesn’t work for me, how should I proceed with this?
I managed to get the idToken by doing this:
final result = await Amplify.Auth.fetchAuthSession(
options: const auth.CognitoSessionOptions(getAWSCredentials: true),
) as auth.CognitoAuthSession;
var userPoolTokens = result.userPoolTokens!.idToken.raw;
I managed to get the idToken by doing this:
final result = await Amplify.Auth.fetchAuthSession( options: const auth.CognitoSessionOptions(getAWSCredentials: true), ) as auth.CognitoAuthSession; var userPoolTokens = result.userPoolTokens!.idToken.raw;
An example like this deserves to be on the docs page [https://docs.amplify.aws/flutter/build-a-backend/graphqlapi/customize-authz-modes/#amazon-cognito-user-pools].
It explains several different options but stops just short of something like this:
await Amplify.addPlugin(
AmplifyAPI(
authProviders: const [
CustomOIDCProvider()
],
),
);
...
class CustomOIDCProvider extends OIDCAuthProvider {
const CustomOIDCProvider();
@override
Future<String?> getLatestAuthToken() async {
final session = await Amplify.Auth.fetchAuthSession() as CognitoAuthSession;
return session?.userPoolTokensResult?.value?.idToken?.raw;
}
}
I am unable to retrieve the JWT token in my Flutter application. When I use the code below to obtain the idToken for authorization in API headers, I receive a JSON Web Token that does not work with my API. Strangely, this issue does not occur in my native Android application, and I'm unsure why Flutter is having difficulties. Can anyone help me on the token issue?
Future
@arulchezhiyan are you using the .raw getter or .encode method? Please see https://github.com/aws-amplify/amplify-flutter/issues/5023#issuecomment-2166559152 and if that does not answer your question please open a new issue and fill out the issue template. Thanks.
Description
Hi I am confused how could I get the jwt token .
Categories
Steps to Reproduce
No response
Screenshots
No response
Platforms
Android Device/Emulator API Level
No response
Environment
Dependencies
Device
emulator pixel
OS
Android
Deployment Method
Amplify CLI
CLI Version
No response
Additional Context
No response
Amplify Config
{ "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": {} }, "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "", "Region": "ap-southeast-1" } } }, "CognitoUserPool": { "Default": { "PoolId": "", "AppClientId": "", "Region": "" } }, "Auth": { "Default": { "authenticationFlowType": "USER_SRP_AUTH", "socialProviders": [], "usernameAttributes": [ "EMAIL" ], "signupAttributes": [ "EMAIL" ], "passwordProtectionSettings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [] }, "mfaConfiguration": "OPTIONAL", "mfaTypes": [ "TOTP" ], "verificationMechanisms": [ "EMAIL" ] } } } } } }''';