简体   繁体   English

如何获取 Flutter 中的 AWS Cognito 用户组?

[英]How to get the AWS Cognito User group in Flutter?

I am building a mobile application with Flutter and AWS.我正在使用 Flutter 和 AWS 构建一个移动应用程序。 I am using the AWS Cognito user pool to authenticate users in the app.我正在使用 AWS Cognito 用户池对应用程序中的用户进行身份验证。 There are types of users in my app, which is the type USER and ADMIN .我的应用程序中有用户类型,即USERADMIN类型。 The Admin users are in an ADMIN user group. Admin 用户位于 ADMIN 用户组中。 After the user is authenticated, I want to get the user group's ADMIN to a different view.用户通过身份验证后,我想将用户组的 ADMIN 设置为不同的视图。

How to get the user group in Flutter AWS?如何获取Flutter AWS中的用户组?

I was able to get the user group after decoding the accessToken.在解码 accessToken 后,我能够获得用户组。 The token contains cognito:groups attribute if the user inside a group如果用户在组内,则令牌包含cognito:groups属性

 AuthSession authSessions = await Amplify.Auth.fetchAuthSession( options: CognitoSessionOptions(getAWSCredentials: true));

    if(authSessions.isSignedIn) {
      final accessToken = (authSessions as CognitoAuthSession).userPoolTokens?.accessToken;
      print("identityId ==>  ${accessToken}");
    }

Docs: https://docs.amplify.aws/lib/auth/access_credentials/q/platform/flutter/文档: https://docs.amplify.aws/lib/auth/access_credentials/q/platform/flutter/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM