Class: YiffSpace::Auth::Client
- Inherits:
-
Object
- Object
- YiffSpace::Auth::Client
- Defined in:
- lib/yiffspace/auth/client.rb
Instance Attribute Summary collapse
-
#after_auth_action ⇒ Object
Returns the value of attribute after_auth_action.
-
#after_logout_action ⇒ Object
Returns the value of attribute after_logout_action.
-
#auth_session_key ⇒ Object
Returns the value of attribute auth_session_key.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_name ⇒ Object
Returns the value of attribute client_name.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#return_path_session_key ⇒ Object
Returns the value of attribute return_path_session_key.
-
#scopes ⇒ Object
Returns the value of attribute scopes.
-
#server_url ⇒ Object
Returns the value of attribute server_url.
-
#state_generator ⇒ Object
Returns the value of attribute state_generator.
-
#state_session_key ⇒ Object
Returns the value of attribute state_session_key.
-
#token_session_key ⇒ Object
Returns the value of attribute token_session_key.
-
#update_discord_images ⇒ Object
Returns the value of attribute update_discord_images.
-
#user_session_key ⇒ Object
Returns the value of attribute user_session_key.
Instance Method Summary collapse
- #exchange(code) ⇒ Object
-
#initialize(name) ⇒ Client
constructor
A new instance of Client.
- #oidc_client ⇒ Object
- #openid_config ⇒ Object
- #url(state: nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/yiffspace/auth/client.rb', line 14 def initialize(name) @name = name.to_sym @server_url = "https://auth.yiff.space" @redirect_uri = "http://127.0.0.1:3000/auth/cb" @scopes = %i[openid discord offline_access entitlements] @auth_session_key = :"yiffspace_auth_#{name}" @user_session_key = :"yiffspace_user_#{name}" @token_session_key = :"yiffspace_token_#{name}" @return_path_session_key = :"yiffspace_return_path_#{name}" @state_session_key = :"yiffspace_state_#{name}" @state_generator = -> { SecureRandom.hex(48) } @update_discord_images = true end |
Instance Attribute Details
#after_auth_action ⇒ Object
Returns the value of attribute after_auth_action.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def after_auth_action @after_auth_action end |
#after_logout_action ⇒ Object
Returns the value of attribute after_logout_action.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def after_logout_action @after_logout_action end |
#auth_session_key ⇒ Object
Returns the value of attribute auth_session_key.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def auth_session_key @auth_session_key end |
#client_id ⇒ Object
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def client_id @client_id end |
#client_name ⇒ Object
Returns the value of attribute client_name.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def client_name @client_name end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def client_secret @client_secret end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/yiffspace/auth/client.rb', line 12 def name @name end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def redirect_uri @redirect_uri end |
#return_path_session_key ⇒ Object
Returns the value of attribute return_path_session_key.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def return_path_session_key @return_path_session_key end |
#scopes ⇒ Object
Returns the value of attribute scopes.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def scopes @scopes end |
#server_url ⇒ Object
Returns the value of attribute server_url.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def server_url @server_url end |
#state_generator ⇒ Object
Returns the value of attribute state_generator.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def state_generator @state_generator end |
#state_session_key ⇒ Object
Returns the value of attribute state_session_key.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def state_session_key @state_session_key end |
#token_session_key ⇒ Object
Returns the value of attribute token_session_key.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def token_session_key @token_session_key end |
#update_discord_images ⇒ Object
Returns the value of attribute update_discord_images.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def update_discord_images @update_discord_images end |
#user_session_key ⇒ Object
Returns the value of attribute user_session_key.
6 7 8 |
# File 'lib/yiffspace/auth/client.rb', line 6 def user_session_key @user_session_key end |
Instance Method Details
#exchange(code) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/yiffspace/auth/client.rb', line 47 def exchange(code) oidc_client. = code token = oidc_client.access_token! user = token.userinfo! id = user.raw_attributes["discord"]["id"] authinfo = AuthInfo.new(token: token, entitlements: user.raw_attributes["entitlements"], roles: user.raw_attributes["roles"], id: id) userinfo = UserInfo.new(user: user, id: id, discord: user.raw_attributes["discord"], client_id: oidc_client.identifier) Auth::ExchangeResponse.new(authinfo, userinfo) end |
#oidc_client ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yiffspace/auth/client.rb', line 32 def oidc_client @oidc_client ||= OpenIDConnect::Client.new( identifier: client_id, secret: client_secret, redirect_uri: redirect_uri, authorization_endpoint: openid_config., token_endpoint: openid_config.token_endpoint, userinfo_endpoint: openid_config.userinfo_endpoint, ) end |
#openid_config ⇒ Object
28 29 30 |
# File 'lib/yiffspace/auth/client.rb', line 28 def openid_config @openid_config ||= OpenIDConnect::Discovery::Provider::Config.discover!("#{server_url}/application/o/#{client_name}/") end |
#url(state: nil) ⇒ Object
43 44 45 |
# File 'lib/yiffspace/auth/client.rb', line 43 def url(state: nil) oidc_client.(scope: scopes, state: state) end |