Module: Dina::Authentication

Defined in:
lib/dina/authentication/authentication.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.authorization_urlObject

Returns the value of attribute authorization_url.



50
51
52
# File 'lib/dina/authentication/authentication.rb', line 50

def authorization_url
  @authorization_url
end

.client_idObject

Returns the value of attribute client_id.



50
51
52
# File 'lib/dina/authentication/authentication.rb', line 50

def client_id
  @client_id
end

.endpoint_urlObject

Returns the value of attribute endpoint_url.



50
51
52
# File 'lib/dina/authentication/authentication.rb', line 50

def endpoint_url
  @endpoint_url
end

.realmObject

Returns the value of attribute realm.



50
51
52
# File 'lib/dina/authentication/authentication.rb', line 50

def realm
  @realm
end

.server_nameObject

Returns the value of attribute server_name.



50
51
52
# File 'lib/dina/authentication/authentication.rb', line 50

def server_name
  @server_name
end

.token_store_fileObject

Returns the value of attribute token_store_file.



50
51
52
# File 'lib/dina/authentication/authentication.rb', line 50

def token_store_file
  @token_store_file
end

Class Method Details

.config(options = {}) ⇒ Object

Sets Authentication configuration Options hash as follows:

token_store_file: "file to store the token",
user: "username provided by DINA admin in Keycloak",
password: "password provided by DINA admin in Keycloak",
server_name: "used locally to reference the token",
client_id: "provided by DINA admin in Keycloak",
endpoint_url: "DINA API URL",
authorization_url: "Keycloak authorization URL".
realm: "provided by DINA admin in Keycloak"

Parameters:

  • options (Hash) (defaults to: {})

    the configuration options



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dina/authentication/authentication.rb', line 20

def self.config(options = {})
  @token_store_file = options[:token_store_file]
  @user = options[:user]
  @password = options[:password]
  @server_name = options[:server_name]
  @client_id = options[:client_id]
  @endpoint_url = options[:endpoint_url]
  @authorization_url = options[:authorization_url]
  @realm = options[:realm]
  Keycloak.auth_server_url = @authorization_url
  Keycloak.realm = @realm
end

.headerString

Gets, sets, and renews a Bearer access token as required and produces a Header string

Returns:

  • (String)

    the Bearer token



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dina/authentication/authentication.rb', line 37

def self.header
  if access_token.nil? || refresh_token.nil?
    set_token
  end

  if Time.now >= Time.parse(auth_expiry)
    renew_token
  end

  "Bearer " + access_token
end