Class: DuoUniversalRails::AuthRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/duo_universal_rails/requests/auth_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

Constructor Details

This class inherits a constructor from DuoUniversalRails::Request

Instance Method Details

#build_auth_url_query_params(username:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/duo_universal_rails/requests/auth_request.rb', line 10

def build_auth_url_query_params(username:)
  {
      response_type: 'code',
      client_id: client.client_id,
      request: request_jwt(username: username),
      redirect_uri: client.redirect_uri,
      scope: 'openid'

  }
end

#create_url(username:) ⇒ Object



4
5
6
7
8
# File 'lib/duo_universal_rails/requests/auth_request.rb', line 4

def create_url(username:)
  query_params = build_auth_url_query_params(username: username)
  url_query = query_params.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
  [client.auth_url, "?", url_query].join("")
end

#request_jwt(username:) ⇒ Object



81
82
83
84
# File 'lib/duo_universal_rails/requests/auth_request.rb', line 81

def request_jwt(username:)
  get_payload = request_params(username: username)
  client.create_jwt_payload(payload: get_payload)
end

#request_params(username:) ⇒ Object

If provided and the value is true, then the authorization code will be returned under the attribute name of duo_code. KEY - use_duo_code_attribute, TYPE - Boolean, REQUIRED - No



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/duo_universal_rails/requests/auth_request.rb', line 66

def request_params(username:)
   {
      response_type: 'code',
      scope: 'openid',
      exp: client.expire_in_sec,
      client_id: client.client_id,
      redirect_uri: client.redirect_uri,
      state: client.state,
      duo_uname: username,
      iss: client.client_id,
      aud: client.https_api_hostname,
      use_duo_code_attribute: true
  }
end