Class: CognitoIdp::Client
- Inherits:
-
Object
- Object
- CognitoIdp::Client
- Defined in:
- lib/cognito_idp/client.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#domain ⇒ Object
readonly
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.
- #inspect ⇒ Object
- #logout_uri(**options) ⇒ Object
- #revoke_token(token) ⇒ Object
Constructor Details
#initialize(client_id:, domain:, client_secret: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 |
# File 'lib/cognito_idp/client.rb', line 10 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 (readonly)
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/cognito_idp/client.rb', line 8 def adapter @adapter end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
8 9 10 |
# File 'lib/cognito_idp/client.rb', line 8 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
8 9 10 |
# File 'lib/cognito_idp/client.rb', line 8 def client_secret @client_secret end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
8 9 10 |
# File 'lib/cognito_idp/client.rb', line 8 def domain @domain end |
Instance Method Details
#authorization_uri(redirect_uri:, **options) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/cognito_idp/client.rb', line 26 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cognito_idp/client.rb', line 35 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, ) handle_error_response(response) token = Token.new(response.body) yield(token) if block_given? token end |
#get_user_info(token) {|user_info| ... } ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cognito_idp/client.rb', line 53 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}"}) handle_error_response(response) user_info = UserInfo.new(response.body) yield(user_info) if block_given? user_info end |
#inspect ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/cognito_idp/client.rb', line 18 def inspect "#<#{self.class}:0x#{object_id.to_s(16)} " \ "@adapter=#{adapter.inspect}, " \ "@client_id=#{client_id.inspect}, " \ "@client_secret=#{client_secret.nil? ? "nil" : "[REDACTED]"}, " \ "@domain=#{domain.inspect}>" end |
#logout_uri(**options) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/cognito_idp/client.rb', line 81 def logout_uri(**) LogoutUri.new( client_id: client_id, domain: domain, ** ).to_s end |
#revoke_token(token) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cognito_idp/client.rb', line 68 def revoke_token(token) refresh_token = case token when Token token.refresh_token else token end params = {client_id: client_id, token: refresh_token} response = connection.post("/oauth2/revoke", params, ) handle_error_response(response) end |