Class: DuoUniversalRails::TokenRequest
- Inherits:
-
Request
- Object
- Request
- DuoUniversalRails::TokenRequest
show all
- Defined in:
- lib/duo_universal_rails/requests/token_request.rb
Instance Attribute Summary
Attributes inherited from Request
#client
Instance Method Summary
collapse
Methods inherited from Request
#default_headers, #get_request, #handle_response, #initialize, #post_request
Instance Method Details
#client_assertion_payload ⇒ Object
The time at which the JWT was created. KEY - exp, TYPE - Integer, REQUIRED - No
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/duo_universal_rails/requests/token_request.rb', line 66
def client_assertion_payload
{
iss: client.client_id,
sub: client.client_id,
aud: client.token_url,
exp: client.expire_in_sec,
jti: client.state,
iat: client.time_now_in_sec
}
end
|
#exchange_authorization_code_for_2fa_result(code: client.state, username:) ⇒ Object
5
6
7
8
9
|
# File 'lib/duo_universal_rails/requests/token_request.rb', line 5
def exchange_authorization_code_for_2fa_result(code: client.state, username:)
request = post_request([client.token_path].join(""), params: request_params(code: code))
parse_request = JSON.parse(request.body)
verify_token(token: parse_request["id_token"])[0]
end
|
#jwt_client_assertion ⇒ Object
77
78
79
|
# File 'lib/duo_universal_rails/requests/token_request.rb', line 77
def jwt_client_assertion
client.create_jwt_payload(payload: client_assertion_payload)
end
|
#request_params(code:) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/duo_universal_rails/requests/token_request.rb', line 31
def request_params(code:)
{
grant_type: 'authorization_code',
code: code,
redirect_uri: client.redirect_uri,
client_assertion_type: Constant::CLIENT_ASSERT_TYPE,
client_assertion: jwt_client_assertion,
client_id: client.client_id
}
end
|
#verify_token(token:) ⇒ Object
82
83
84
|
# File 'lib/duo_universal_rails/requests/token_request.rb', line 82
def verify_token(token:)
client.decode_jwt_token(token: token)
end
|