@@ -23,7 +23,7 @@ module CognitoIdentity
23
23
#
24
24
# ## Refreshing Credentials from Identity Service
25
25
#
26
- # The CognitoIdentityCredentials will auto-refresh the AWS credentials from
26
+ # The ` CognitoIdentityCredentials` will auto-refresh the AWS credentials from
27
27
# Cognito. In addition to AWS credentials expiring after a given amount of
28
28
# time, the login token from the identity provider will also expire.
29
29
# Once this token expires, it will not be usable to refresh AWS credentials,
@@ -32,19 +32,18 @@ module CognitoIdentity
32
32
# supported by most identity providers. Consult the documentation for
33
33
# the identity provider for refreshing tokens. Once the refreshed token is
34
34
# acquired, you should make sure to update this new token in the
35
- # CognitoIdentityCredentials object's {logins} property. The following
35
+ # ` CognitoIdentityCredentials` object's {logins} property. The following
36
36
# code will update the WebIdentityToken, assuming you have retrieved
37
37
# an updated token from the identity provider:
38
38
#
39
- # AWS.config.credentials .logins['graph.facebook.com'] = updatedToken;
40
- # AWS.config.credentials .refresh! # required only if authentication state has changed
39
+ # cognito_credentials .logins['graph.facebook.com'] = updatedToken;
40
+ # cognito_credentials .refresh! # required only if authentication state has changed
41
41
#
42
- # The CognitoIdentityCredentials also provides a `before_refresh` callback
42
+ # The ` CognitoIdentityCredentials` also provides a `before_refresh` callback
43
43
# that can be used to help manage refreshing identity provider tokens.
44
44
# `before_refresh` is called when AWS credentials are required and need
45
45
# to be refreshed and it has access to the CognitoIdentityCredentials object.
46
46
class CognitoIdentityCredentials
47
-
48
47
include CredentialProvider
49
48
include RefreshingCredentials
50
49
@@ -54,8 +53,8 @@ class CognitoIdentityCredentials
54
53
# identifier in the format REGION:GUID
55
54
#
56
55
# @option options [String] :identity_pool_id Required unless identity_id
57
- # is provided. A Amazon Cognito
58
- # Identity Pool ID)in the format REGION:GUID.
56
+ # is provided. An Amazon Cognito Identity Pool ID in the
57
+ # format REGION:GUID.
59
58
#
60
59
# @option options [Hash<String,String>] :logins A set of optional
61
60
# name-value pairs that map provider names to provider tokens.
@@ -69,16 +68,15 @@ class CognitoIdentityCredentials
69
68
# that do not support role customization.
70
69
#
71
70
# @option options [Callable] before_refresh Proc called before
72
- # credentials are refreshed from Cognito. Useful for updating logins/
73
- # auth tokens. `before_refresh` is called when AWS credentials are
74
- # required and need to be refreshed. Login tokens can be refreshed using
75
- # the following example:
71
+ # credentials are refreshed from Cognito. `before_refresh` is called
72
+ # when AWS credentials are required and need to be refreshed.
73
+ # Login tokens can be refreshed using the following example:
76
74
#
77
75
# before_refresh = Proc.new do |cognito_credentials| do
78
76
# cognito_credentials.logins['graph.facebook.com'] = update_token
79
77
# end
80
78
#
81
- # @option options [STS::CognitoIdentity ] :client Optional CognitoIdentity
79
+ # @option options [CognitoIdentity::Client ] :client Optional CognitoIdentity
82
80
# client. If not provided, a client will be constructed.
83
81
def initialize ( options = { } )
84
82
@identity_pool_id = options . delete ( :identity_pool_id )
@@ -88,9 +86,9 @@ def initialize(options = {})
88
86
@async_refresh = false
89
87
90
88
client_opts = { }
91
- options . each_pair { |k , v | client_opts [ k ] = v unless CLIENT_EXCLUDE_OPTIONS . include? ( k ) }
89
+ options . each_pair { |k , v | client_opts [ k ] = v unless CLIENT_EXCLUDE_OPTIONS . include? ( k ) }
92
90
93
- if ! @identity_pool_id && ! @identity_id
91
+ unless @identity_pool_id || @identity_id
94
92
raise ArgumentError ,
95
93
'Must provide either identity_pool_id or identity_id'
96
94
end
@@ -109,19 +107,21 @@ def initialize(options = {})
109
107
110
108
# @return [String]
111
109
def identity_id
112
- @identity_id ||= @client
113
- . get_id ( identity_pool_id : @identity_pool_id )
114
- . identity_id
110
+ @identity_id ||= @client . get_id (
111
+ identity_pool_id : @identity_pool_id ,
112
+ logins : @logins
113
+ ) . identity_id
115
114
end
116
115
117
116
private
118
117
119
118
def refresh
120
- @before_refresh . call ( self ) if @before_refresh
119
+ @before_refresh & .call ( self )
121
120
122
121
resp = @client . get_credentials_for_identity (
123
122
identity_id : identity_id ,
124
- custom_role_arn : @custom_role_arn
123
+ custom_role_arn : @custom_role_arn ,
124
+ logins : @logins
125
125
)
126
126
127
127
@credentials = Credentials . new (
@@ -134,4 +134,3 @@ def refresh
134
134
end
135
135
end
136
136
end
137
-
0 commit comments