Class: Oxd::ClientOxdCommands

Inherits:
OxdConnector show all
Defined in:
lib/oxd/client_oxd_commands.rb

Overview

This class carries out the commands to talk with the oxD server. The oxD request commands are provided as class methods that can be called to send the command to the oxD server via socket and the reponse is returned as a dict by the called method.

Instance Method Summary collapse

Methods inherited from OxdConnector

#getData, #getResponseData, #is_json?, #logger, #oxd_socket_request, #request, #validate_command

Constructor Details

#initializeClientOxdCommands

class constructor



13
14
15
# File 'lib/oxd/client_oxd_commands.rb', line 13

def initialize
  super
end

Instance Method Details

#get_authorization_url(acr_values = [""]) ⇒ String

method to get authorization url that the user must be redirected to for authorization and authentication



53
54
55
56
57
58
59
60
61
# File 'lib/oxd/client_oxd_commands.rb', line 53

def get_authorization_url(acr_values = [""])
  @command = 'get_authorization_url'
  @params = {
           "oxd_id" => @configuration.oxd_id,
           "acr_values" => acr_values || @configuration.acr_values
        }
    request
    getResponseData['authorization_url']
end

#get_logout_uri(access_token, state = nil, session_state = nil) ⇒ String

method to retrieve logout url from OP. User must be redirected to this url to perform logout



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/oxd/client_oxd_commands.rb', line 104

def get_logout_uri(access_token, state = nil, session_state = nil)
  @command = 'get_logout_uri'
  @params = {
           "oxd_id" => @configuration.oxd_id,
           "id_token_hint" => access_token,             
           "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri, 
           "state" => state,
           "session_state" => session_state
        }
        request
        getResponseData['uri']
end

#get_tokens_by_code(code, scopes, state = nil) ⇒ String

method to retrieve access token. It is called after the user authorizes by visiting the authorization url.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/oxd/client_oxd_commands.rb', line 68

def get_tokens_by_code( code, scopes, state = nil)
          if (code.empty? || scopes.empty? || (!scopes.kind_of? Array))
            logger(:log_msg => "Empty/Wrong value in place of code or scope.")
        end
  @command = 'get_tokens_by_code'
  @params = {
           "oxd_id" => @configuration.oxd_id,
           "code" => code,
           "scopes" => scopes,
           "state" => state
        }          
  request
  getResponseData['access_token']
end

#get_user_info(access_token) ⇒ String

get the information about the user using the access token obtained from the OP



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/oxd/client_oxd_commands.rb', line 86

def (access_token)
  if access_token.empty?
           logger(:log_msg => "Empty access code sent for get_user_info", :error => "Empty access code")
       end
  @command = 'get_user_info'
    @params = {
           "oxd_id" => @configuration.oxd_id,
           "access_token" => access_token
        }
        request
  getResponseData['claims']
end

#getOxdIdString



46
47
48
# File 'lib/oxd/client_oxd_commands.rb', line 46

def getOxdId
    return @configuration.oxd_id
end

#register_siteString

method to register the website and generate a unique ID for that website



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/oxd/client_oxd_commands.rb', line 19

def register_site     
  if(!@configuration.oxd_id.empty?) # Check if client is already registered
    return @configuration.oxd_id
  else
    @command = 'register_site'
    @configuration.scope = [ "openid", "profile","email"]
    @params = {
          "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
            "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
            "application_type" => @configuration.application_type,
            "redirect_uris" => @configuration.redirect_uris,
            "acr_values" => @configuration.acr_values,
            "scope" => @configuration.scope,
            "client_jwks_uri" => @configuration.client_jwks_uri,
            "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
            "client_request_uris" => @configuration.client_request_uris,
            "contacts" => @configuration.contacts,
            "grant_types" => @configuration.grant_types,
            "response_types"=> @configuration.response_types,
            "client_logout_uris"=> @configuration.client_logout_uris
        }
        request
        @configuration.oxd_id = getResponseData['oxd_id']
    end         
end

#update_site_registrationBoolean

method to update the website’s information with OpenID Provider. This should be called after changing the values in the oxd_config file.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/oxd/client_oxd_commands.rb', line 120

def update_site_registration
    @command = 'update_site_registration'
        @params = {
        "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
        "oxd_id" => @configuration.oxd_id,
           "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
           "application_type" => @configuration.application_type,
           "redirect_uris" => @configuration.redirect_uris,
           "acr_values" => @configuration.acr_values,
           "scope" => @configuration.scope,
           "client_jwks_uri" => @configuration.client_jwks_uri,
           "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
           "client_request_uris" => @configuration.client_request_uris,
           "contacts" => @configuration.contacts,
           "grant_types" => @configuration.grant_types,
           "response_types"=> @configuration.response_types,
           "client_logout_uris"=> @configuration.client_logout_uris
       }
       request
       if @response_object['status'] == "ok"
        @configuration.oxd_id = getResponseData['oxd_id']
           return true
       else
           return false
       end
end