Class: Ask::MCP::Auth::OAuth
- Inherits:
-
Object
- Object
- Ask::MCP::Auth::OAuth
- Defined in:
- lib/ask/mcp/auth/oauth.rb
Instance Attribute Summary collapse
-
#auth_url ⇒ Object
readonly
Returns the value of attribute auth_url.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#token_url ⇒ Object
readonly
Returns the value of attribute token_url.
Instance Method Summary collapse
- #apply(headers = {}) ⇒ Object
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
-
#initialize(client_id:, client_secret: nil, token_url:, auth_url: nil, redirect_uri: nil, scopes: []) ⇒ OAuth
constructor
A new instance of OAuth.
- #refresh! ⇒ Object
Constructor Details
#initialize(client_id:, client_secret: nil, token_url:, auth_url: nil, redirect_uri: nil, scopes: []) ⇒ OAuth
Returns a new instance of OAuth.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ask/mcp/auth/oauth.rb', line 9 def initialize(client_id:, client_secret: nil, token_url:, auth_url: nil, redirect_uri: nil, scopes: []) @client_id = client_id @client_secret = client_secret @token_url = token_url @auth_url = auth_url @redirect_uri = redirect_uri @scopes = scopes @access_token = nil @refresh_token = nil @expires_at = nil end |
Instance Attribute Details
#auth_url ⇒ Object (readonly)
Returns the value of attribute auth_url.
7 8 9 |
# File 'lib/ask/mcp/auth/oauth.rb', line 7 def auth_url @auth_url end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/ask/mcp/auth/oauth.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/ask/mcp/auth/oauth.rb', line 7 def client_secret @client_secret end |
#token_url ⇒ Object (readonly)
Returns the value of attribute token_url.
7 8 9 |
# File 'lib/ask/mcp/auth/oauth.rb', line 7 def token_url @token_url end |
Instance Method Details
#apply(headers = {}) ⇒ Object
26 27 28 |
# File 'lib/ask/mcp/auth/oauth.rb', line 26 def apply(headers = {}) headers.merge("Authorization" => "Bearer #{@access_token}") end |
#authenticate! ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ask/mcp/auth/oauth.rb', line 30 def authenticate! if @client_secret authenticate_client_credentials elsif @auth_url else raise AuthError, "No authentication method available" end self end |
#authenticated? ⇒ Boolean
22 23 24 |
# File 'lib/ask/mcp/auth/oauth.rb', line 22 def authenticated? !@access_token.nil? && !expired? end |
#refresh! ⇒ Object
41 42 43 44 45 |
# File 'lib/ask/mcp/auth/oauth.rb', line 41 def refresh! raise AuthError, "No refresh token available" unless @refresh_token perform_token_refresh self end |