AWS身份池:这两种方法有什么区别?
创始人
2024-09-27 08:31:15
0

AWS身份池是一种为AWS资源提供临时安全凭据的服务,可以实现对不同身份的用户进行身份验证和授权。在使用身份池时,有两种不同的方法可供选择:使用认证ID和身份池ID,或者使用Cognito身份提供程序。

使用认证ID和身份池ID的方法:

import boto3
  
# 定义认证ID和身份池ID
identity_pool_id = 'IDENTITY_POOL_ID'
developer_provider_name = 'DEVELOPER_PROVIDER_NAME'
  
# 创建CognitoIdentityClient
client = boto3.client('cognito-identity')
  
# 获取身份ID
identities = client.get_id(AccountId='ACCOUNT_ID', IdentityPoolId=identity_pool_id)
identity_id = identities['IdentityId']
  
# 获取身份凭证
credentials = client.get_credentials_for_identity(IdentityId=identity_id)
access_key = credentials['Credentials']['AccessKeyId']
secret_key = credentials['Credentials']['SecretKey']
session_token = credentials['Credentials']['SessionToken']

使用Cognito身份提供程序的方法:

import boto3
  
# 定义身份池ID和身份池的身份提供程序
identity_pool_id = 'IDENTITY_POOL_ID'
provider_name = 'cognito-idp.{0}.amazonaws.com/{1}'.format(aws_region, user_pool_id)
  
# 创建CognitoIdentityProviderClient
client = boto3.client('cognito-idp')
  
# 获取用户令牌
token = get_user_access_token()
  
# 获取身份凭证
response = client.get_id(IdentityPoolId=identity_pool_id, Logins={provider_name: token})
identity_id = response['IdentityId']
credentials = client.get_credentials_for_identity(IdentityId=identity_id)
access_key = credentials['Credentials']['AccessKeyId']
secret_key = credentials['Credentials']['SecretKey']
session_token = credentials['Credentials']['SessionToken']

相关内容

热门资讯

玩家必看“德州wpk透视辅助器... 德州wpk透视辅助器是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的用户可以加...
一分钟了解“wepoker可以... 一分钟了解“wepoker可以透视开挂吗”开挂辅助器(透视)安装教程是一款可以让一直输的玩家,快速成...
一分钟揭秘“wepoker透视... 无需打开直接搜索加微信客服(136704302)咨询了解wepoker透视开挂挂视频辅助器目前(微信...
传递经验“WePoKer辅助挂... >>您好:WePoKer辅助挂怎么下载软件加扣扣群确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
玩家必看“WePoker脚本实... 玩家必看“WePoker脚本实战效果”开挂辅助工具(透视)必赢教程是一款可以让一直输的玩家,快速成为...
攻略讲解“wepoker透视挂... 您好:wepoker透视挂方法这款游戏是可以开挂的,软件加【添加微信客服136704302】确实是有...
玩家必看科普“wepoker辅... >>您好:wepoker辅助挂是什么软件加扣扣群确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用...
总算了解“wepoker有透视... 总算了解“wepoker有透视软件挂吗”开挂辅助脚本(透视)细节揭秘是一款可以让一直输的玩家,快速成...
推荐十款“wepoker有没有... 您好:wepoker有没有透视挂这款游戏是可以开挂的,软件加【添加微信客服136704302】确实是...
普及知识“wepoker辅助插... 您好:wepoker辅助插件怎么用这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现...