Class: OmniauthOidc::Client
- Inherits:
-
Object
- Object
- OmniauthOidc::Client
- Defined in:
- lib/omniauth/oidc/client.rb
Overview
Custom OIDC client using Net::HTTP
Instance Attribute Summary collapse
-
#authorization_endpoint ⇒ Object
Returns the value of attribute authorization_endpoint.
-
#host ⇒ Object
Returns the value of attribute host.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#token_endpoint ⇒ Object
Returns the value of attribute token_endpoint.
-
#userinfo_endpoint ⇒ Object
Returns the value of attribute userinfo_endpoint.
Instance Method Summary collapse
-
#access_token!(params = {}) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #authorization_uri(params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #userinfo!(access_token) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 |
# File 'lib/omniauth/oidc/client.rb', line 11 def initialize( = {}) @identifier = [:identifier] || ["identifier"] @secret = [:secret] || ["secret"] @authorization_endpoint = [:authorization_endpoint] || ["authorization_endpoint"] @token_endpoint = [:token_endpoint] || ["token_endpoint"] @userinfo_endpoint = [:userinfo_endpoint] || ["userinfo_endpoint"] @redirect_uri = [:redirect_uri] || ["redirect_uri"] end |
Instance Attribute Details
#authorization_endpoint ⇒ Object
Returns the value of attribute authorization_endpoint.
8 9 10 |
# File 'lib/omniauth/oidc/client.rb', line 8 def @authorization_endpoint end |
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/omniauth/oidc/client.rb', line 8 def host @host end |
#identifier ⇒ Object
Returns the value of attribute identifier.
8 9 10 |
# File 'lib/omniauth/oidc/client.rb', line 8 def identifier @identifier end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
8 9 10 |
# File 'lib/omniauth/oidc/client.rb', line 8 def redirect_uri @redirect_uri end |
#secret ⇒ Object
Returns the value of attribute secret.
8 9 10 |
# File 'lib/omniauth/oidc/client.rb', line 8 def secret @secret end |
#token_endpoint ⇒ Object
Returns the value of attribute token_endpoint.
8 9 10 |
# File 'lib/omniauth/oidc/client.rb', line 8 def token_endpoint @token_endpoint end |
#userinfo_endpoint ⇒ Object
Returns the value of attribute userinfo_endpoint.
8 9 10 |
# File 'lib/omniauth/oidc/client.rb', line 8 def userinfo_endpoint @userinfo_endpoint end |
Instance Method Details
#access_token!(params = {}) ⇒ Object
rubocop:disable Metrics/MethodLength
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/omniauth/oidc/client.rb', line 42 def access_token!(params = {}) # rubocop:disable Metrics/MethodLength body_params = { grant_type: "authorization_code", code: params[:code], redirect_uri: params[:redirect_uri] || @redirect_uri, client_id: identifier, client_secret: secret } # Add PKCE verifier if provided body_params[:code_verifier] = params[:code_verifier] if params[:code_verifier] OmniauthOidc::Logging.instrument("token.exchange", code: "[FILTERED]") do response = HttpClient.post( token_endpoint, body: URI.encode_www_form(body_params), headers: { "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json" } ) ResponseObjects::AccessToken.new(response) end rescue HttpClient::HttpError => e raise OmniauthOidc::TokenError, "Token exchange failed: #{e.}" end |
#authorization_uri(params = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/omniauth/oidc/client.rb', line 20 def (params = {}) uri = URI.parse() query_params = { client_id: identifier, response_type: params[:response_type] || "code", scope: params[:scope] || "openid profile email", redirect_uri: params[:redirect_uri] || @redirect_uri, state: params[:state], nonce: params[:nonce] }.compact # Add PKCE parameters if provided query_params[:code_challenge] = params[:code_challenge] if params[:code_challenge] query_params[:code_challenge_method] = params[:code_challenge_method] if params[:code_challenge_method] # Add any additional params query_params.merge!(params[:extra_params]) if params[:extra_params] uri.query = URI.encode_www_form(query_params) uri.to_s end |
#userinfo!(access_token) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/omniauth/oidc/client.rb', line 70 def userinfo!(access_token) OmniauthOidc::Logging.instrument("userinfo.fetch", endpoint: userinfo_endpoint) do response = HttpClient.get( userinfo_endpoint, headers: { "Authorization" => "Bearer #{access_token}", "Accept" => "application/json" } ) ResponseObjects::UserInfo.new(response) end rescue HttpClient::HttpError => e raise OmniauthOidc::TokenError, "Failed to fetch user info: #{e.}" end |