Methods
Public Class
Public Instance
Attributes
| access_token | [R] | |
| audience | [R] | |
| client_id | [R] | |
| client_secret | [R] | |
| grant_type | [R] | |
| refresh_token | [R] | |
| scope | [R] |
Public Class methods
new( issuer:, client_id:, client_secret:, access_token: nil, refresh_token: nil, scope: nil, audience: nil, token_endpoint: nil, response_type: nil, grant_type: nil, token_endpoint_auth_method: nil )
[show source]
# File lib/httpx/plugins/oauth.rb 21 def initialize( 22 issuer:, 23 client_id:, 24 client_secret:, 25 access_token: nil, 26 refresh_token: nil, 27 scope: nil, 28 audience: nil, 29 token_endpoint: nil, 30 response_type: nil, 31 grant_type: nil, 32 token_endpoint_auth_method: nil 33 ) 34 @issuer = URI(issuer) 35 @client_id = client_id 36 @client_secret = client_secret 37 @token_endpoint = URI(token_endpoint) if token_endpoint 38 @response_type = response_type 39 @scope = case scope 40 when String 41 scope.split 42 when Array 43 scope 44 end 45 @audience = audience 46 @access_token = access_token 47 @refresh_token = refresh_token 48 @token_endpoint_auth_method = String(token_endpoint_auth_method) if token_endpoint_auth_method 49 @grant_type = grant_type || (@refresh_token ? "refresh_token" : "client_credentials") 50 51 unless @token_endpoint_auth_method.nil? || SUPPORTED_AUTH_METHODS.include?(@token_endpoint_auth_method) 52 raise Error, "#{@token_endpoint_auth_method} is not a supported auth method" 53 end 54 55 return if SUPPORTED_GRANT_TYPES.include?(@grant_type) 56 57 raise Error, "#{@grant_type} is not a supported grant type" 58 end
Public Instance methods
load(http)
[show source]
# File lib/httpx/plugins/oauth.rb 68 def load(http) 69 return if @grant_type && @scope 70 71 metadata = http.get("#{@issuer}/.well-known/oauth-authorization-server").raise_for_status.json 72 73 @token_endpoint = metadata["token_endpoint"] 74 @scope = metadata["scopes_supported"] 75 @grant_type = Array(metadata["grant_types_supported"]).find { |gr| SUPPORTED_GRANT_TYPES.include?(gr) } 76 @token_endpoint_auth_method = Array(metadata["token_endpoint_auth_methods_supported"]).find do |am| 77 SUPPORTED_AUTH_METHODS.include?(am) 78 end 79 nil 80 end
merge(other)
[show source]
# File lib/httpx/plugins/oauth.rb 82 def merge(other) 83 obj = dup 84 85 case other 86 when OAuthSession 87 other.instance_variables.each do |ivar| 88 val = other.instance_variable_get(ivar) 89 next unless val 90 91 obj.instance_variable_set(ivar, val) 92 end 93 when Hash 94 other.each do |k, v| 95 obj.instance_variable_set(:"@#{k}", v) if obj.instance_variable_defined?(:"@#{k}") 96 end 97 end 98 obj 99 end
token_endpoint()
[show source]
# File lib/httpx/plugins/oauth.rb 60 def token_endpoint 61 @token_endpoint || "#{@issuer}/token" 62 end
token_endpoint_auth_method()
[show source]
# File lib/httpx/plugins/oauth.rb 64 def token_endpoint_auth_method 65 @token_endpoint_auth_method || "client_secret_basic" 66 end