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