Class: OmniAuth::Strategies::Mixin::Client

Inherits:
OAuth2::Client
  • Object
show all
Defined in:
lib/omniauth/strategies/mixin/client.rb

Overview

OAuth2 client implementation for Mixin Network authentication. Handles token exchange and API communication with Mixin endpoints.

Instance Method Summary collapse

Instance Method Details

#get_token(params, access_token_opts = {}, _extract_access_token = nil) ⇒ Object

Raises:

  • (::OAuth2::Error)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omniauth/strategies/mixin/client.rb', line 12

def get_token(params, access_token_opts = {}, _extract_access_token = nil)
  response = request(:post, token_url, token_params(params))
  parsed = JSON.parse(response.body)

  if parsed["error"]
    error = parsed["error"]
    raise ::OAuth2::Error,
          "Mixin API Error: #{error["description"]} (Status: #{error["status"]}, Code: #{error["code"]})"
  end

  token_data = parsed["data"]
  raise ::OAuth2::Error, "Invalid response format from Mixin API: missing data field" unless token_data

  ::OAuth2::AccessToken.new(
    self,
    token_data["access_token"],
    {
      refresh_token: token_data["refresh_token"],
      expires_in: token_data["expires_in"],
      token_type: token_data["token_type"] || "Bearer"
    }.merge(access_token_opts)
  )
end