我可能已經找到了一種方法來做到這一點。
1)添加到您的Gemfile:
gem 'aws-sdk', '~> 2'
2)添加這3 ENV變量:
export AWS_REGION=us-west-2
export AWS_ACCESS_KEY_ID="Your AWS Access Key ID"
export AWS_SECRET_ACCESS_KEY= "Your AWS Secret Access Key"
3)創建一個新文件。我把以下內容放在app/modules/Aws.rb中
require 'aws-sdk'
cognitoidentityprovider = Aws::CognitoIdentityProvider::Client.new(region: ENV['AWS_REGION'])
begin
cognito_user = cognitoidentityprovider.get_user({
access_token: "Token coming from the APP"
})
email_verified = cognito_user.user_attributes
.detect{ |attribute_type| attribute_type["name"] === "email_verified" && attribute_type["value"] === "true" }
if email_verified.nil?
raise "Email is not verified"
else
puts "EMAIL IS GOOD!"
puts cognito_user.username
end
rescue StandardError => msg
puts "ERROR!"
puts msg
end
我可以在用irb測試時返回用戶郵件。
不知道這是否是正確的方式(或AWS方式)獲取用戶電子郵件....我會很感激任何評論或反饋...