Class: HammerCLIForeman::Api::Oauth::AuthenticationCodeGrant
- Inherits:
-
ApipieBindings::Authenticators::TokenAuth
- Object
- ApipieBindings::Authenticators::TokenAuth
- HammerCLIForeman::Api::Oauth::AuthenticationCodeGrant
- Defined in:
- lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb
Instance Attribute Summary collapse
-
#oidc_authorization_endpoint ⇒ Object
Returns the value of attribute oidc_authorization_endpoint.
-
#oidc_client_id ⇒ Object
Returns the value of attribute oidc_client_id.
-
#oidc_redirect_uri ⇒ Object
Returns the value of attribute oidc_redirect_uri.
-
#oidc_token_endpoint ⇒ Object
Returns the value of attribute oidc_token_endpoint.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #authenticate(request, token) ⇒ Object
- #error(ex) ⇒ Object
-
#initialize(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri) ⇒ AuthenticationCodeGrant
constructor
A new instance of AuthenticationCodeGrant.
- #set_token(input_oidc_token_endpoint, input_oidc_authorization_endpoint, input_oidc_client_id, input_oidc_redirect_uri) ⇒ Object
- #set_token_interactively ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(oidc_token_endpoint, oidc_authorization_endpoint, oidc_client_id, oidc_redirect_uri) ⇒ AuthenticationCodeGrant
Returns a new instance of AuthenticationCodeGrant.
11 12 13 14 15 16 17 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 11 def initialize(oidc_token_endpoint, , oidc_client_id, oidc_redirect_uri) @oidc_token_endpoint = oidc_token_endpoint @oidc_authorization_endpoint = @oidc_client_id = oidc_client_id @oidc_redirect_uri = oidc_redirect_uri super(nil) end |
Instance Attribute Details
#oidc_authorization_endpoint ⇒ Object
Returns the value of attribute oidc_authorization_endpoint.
8 9 10 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 8 def @oidc_authorization_endpoint end |
#oidc_client_id ⇒ Object
Returns the value of attribute oidc_client_id.
8 9 10 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 8 def oidc_client_id @oidc_client_id end |
#oidc_redirect_uri ⇒ Object
Returns the value of attribute oidc_redirect_uri.
8 9 10 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 8 def oidc_redirect_uri @oidc_redirect_uri end |
#oidc_token_endpoint ⇒ Object
Returns the value of attribute oidc_token_endpoint.
8 9 10 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 8 def oidc_token_endpoint @oidc_token_endpoint end |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 8 def token @token end |
Instance Method Details
#authenticate(request, token) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 19 def authenticate(request, token) if HammerCLI.interactive? set_token_interactively else set_token(oidc_token_endpoint, , oidc_client_id, oidc_redirect_uri) end super end |
#error(ex) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 53 def error(ex) if ex.is_a?(RestClient::InternalServerError) @oidc_token_endpoint = @oidc_authorization_endpoint = @oidc_client_id = @oidc_client_id = nil = _("Invalid oidc-client-id or oidc-token-endpoint or oidc-authorization-endpoint.\n") begin = JSON.parse(ex.response.body)['error']['message'] rescue end UnauthorizedError.new( << ) end end |
#set_token(input_oidc_token_endpoint, input_oidc_authorization_endpoint, input_oidc_client_id, input_oidc_redirect_uri) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 32 def set_token(input_oidc_token_endpoint, , input_oidc_client_id, input_oidc_redirect_uri) @oidc_token_endpoint = input_oidc_token_endpoint if input_oidc_token_endpoint @oidc_authorization_endpoint = if @oidc_client_id = input_oidc_client_id if input_oidc_client_id @oidc_redirect_uri = input_oidc_redirect_uri if input_oidc_redirect_uri if @oidc_client_id.to_s.empty? || @oidc_authorization_endpoint.to_s.empty? || @oidc_redirect_uri.to_s.empty? || @oidc_token_endpoint.to_s.empty? @token = nil else @code ||= get_code @token = HammerCLIForeman::OpenidConnect.new( @oidc_token_endpoint, @oidc_client_id).get_token_via_2fa(@code, @oidc_redirect_uri) end end |
#set_token_interactively ⇒ Object
28 29 30 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 28 def set_token_interactively @token ||= set_token(get_oidc_token_endpoint, , get_oidc_client_id, get_oidc_redirect_uri) end |
#user ⇒ Object
47 48 49 50 51 |
# File 'lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb', line 47 def user return nil unless @token payload = JWT.decode(@token, nil, false) payload.first["preferred_username"] end |