Class: OmniAuth::Strategies::Twinfield

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/twinfield.rb

Overview

Twinfield OmniAuth Strategy; follows OmniAuth::Strategies::OAuth2’s base strategy

Defined Under Namespace

Classes: InvalidToken

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validate_token(token) ⇒ Object

Can’t do a JWT token validation in absence of verification keys

Raises:



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/omniauth/strategies/twinfield.rb', line 82

def validate_token(token)
  uri = URI.parse("https://login.twinfield.com/auth/authentication/connect/accesstokenvalidation?token=#{token}")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Get.new(uri)
  http_response = http.request(request)

  response = JSON.parse(http_response.body)

  raise InvalidToken, response["Message"] if response["Message"]

  response
end

Instance Method Details

#build_access_tokenObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/omniauth/strategies/twinfield.rb', line 57

def build_access_token
  verifier = request.params["code"]

  data = {
    headers: authorization_header,
    code: verifier,
    redirect_uri: callback_url.split(/\?/)[0],
    grant_type: "authorization_code"
  }

  client.auth_code.get_token(verifier, data)
end

#infoObject



45
46
47
# File 'lib/omniauth/strategies/twinfield.rb', line 45

def info
  raw_info
end

#raw_infoObject



53
54
55
# File 'lib/omniauth/strategies/twinfield.rb', line 53

def raw_info
  @raw_info ||= self.class.validate_token(access_token.token)
end

#refresh_tokenObject



49
50
51
# File 'lib/omniauth/strategies/twinfield.rb', line 49

def refresh_token
  access_token.to_hash[:refresh_token]
end

#request_phaseObject



37
38
39
# File 'lib/omniauth/strategies/twinfield.rb', line 37

def request_phase
  redirect client.auth_code.authorize_url({ redirect_uri: callback_url }.merge(authorize_params))
end

#uidObject



41
42
43
# File 'lib/omniauth/strategies/twinfield.rb', line 41

def uid
  raw_info["sub"]
end