Class: CognitoIdp::Client
- Inherits:
-
Object
- Object
- CognitoIdp::Client
- Defined in:
- lib/cognito_idp/client.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#domain ⇒ Object
Returns the value of attribute domain.
Instance Method Summary collapse
- #authorization_uri(redirect_uri:, **options) ⇒ Object
- #get_token(grant_type:, **options) {|token| ... } ⇒ Object
- #get_user_info(token) {|user_info| ... } ⇒ Object
-
#initialize(client_id:, domain:, client_secret: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #logout_uri(**options) ⇒ Object
Constructor Details
#initialize(client_id:, domain:, client_secret: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 |
# File 'lib/cognito_idp/client.rb', line 9 def initialize(client_id:, domain:, client_secret: nil, adapter: Faraday.default_adapter, stubs: nil) @adapter = adapter @client_id = client_id @client_secret = client_secret @domain = domain @stubs = stubs end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/cognito_idp/client.rb', line 7 def adapter @adapter end |
#client_id ⇒ Object
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/cognito_idp/client.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/cognito_idp/client.rb', line 7 def client_secret @client_secret end |
#domain ⇒ Object
Returns the value of attribute domain.
7 8 9 |
# File 'lib/cognito_idp/client.rb', line 7 def domain @domain end |
Instance Method Details
#authorization_uri(redirect_uri:, **options) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/cognito_idp/client.rb', line 17 def (redirect_uri:, **) AuthorizationUri.new( client_id: client_id, domain: domain, redirect_uri: redirect_uri, ** ).to_s end |
#get_token(grant_type:, **options) {|token| ... } ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cognito_idp/client.rb', line 26 def get_token(grant_type:, **) params = { client_id: client_id, code: [:code], code_verifier: [:code_verifier], grant_type: grant_type, redirect_uri: [:redirect_uri], refresh_token: [:refresh_token], scope: [:scope] }.compact response = connection.post("/oauth2/token", params, ) return unless response.success? token = Token.new(response.body) yield(token) if block_given? token end |
#get_user_info(token) {|user_info| ... } ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cognito_idp/client.rb', line 44 def get_user_info(token) access_token = case token when Token token.access_token else token end response = connection.post("/oauth2/userInfo", nil, {"Authorization" => "Bearer #{access_token}"}) return unless response.success? user_info = UserInfo.new(response.body) yield(user_info) if block_given? user_info end |