Class: Elelem::MCP::OAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/elelem/mcp/oauth.rb

Defined Under Namespace

Classes: HttpAdapter

Constant Summary collapse

CALLBACK_PORT =
18273
REDIRECT_URI =
"http://127.0.0.1:#{CALLBACK_PORT}/callback"

Instance Method Summary collapse

Constructor Details

#initialize(resource_url, http: HttpAdapter.new) ⇒ OAuth

Returns a new instance of OAuth.



9
10
11
12
13
# File 'lib/elelem/mcp/oauth.rb', line 9

def initialize(resource_url, http: HttpAdapter.new)
  @resource_url = resource_url
  @http = http
  @storage = TokenStorage.new
end

Instance Method Details

#token ⇒ Object



15
16
17
18
19
20
21
# File 'lib/elelem/mcp/oauth.rb', line 15

def token
  stored = @storage.load(@resource_url)
  return stored[:access_token] if stored && !expired?(stored)
  return refresh(stored[:refresh_token]) if stored&.dig(:refresh_token)

  authorize
end