Module: Dina::Authentication
- Defined in:
- lib/dina/authentication/authentication.rb
Class Attribute Summary collapse
-
.endpoint_url ⇒ Object
Returns the value of attribute endpoint_url.
Class Method Summary collapse
-
.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 without terminating slash”, authorization_url: “Keycloak authorization URL without terminating slash”. realm: “provided by DINA admin in Keycloak” }.
-
.header ⇒ String
Gets, sets, and renews a Bearer access token as required and produces a Header string.
Class Attribute Details
.endpoint_url ⇒ Object
Returns the value of attribute endpoint_url.
61 62 63 |
# File 'lib/dina/authentication/authentication.rb', line 61 def endpoint_url @endpoint_url 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 without terminating slash",
authorization_url: "Keycloak authorization URL without terminating slash".
realm: "provided by DINA admin in Keycloak"
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dina/authentication/authentication.rb', line 20 def self.config( = {}) raise ConfigItemMissing, "Missing token_store_file from config." unless [:token_store_file] raise ConfigItemMissing, "Missing user from config." unless [:user] raise ConfigItemMissing, "Missing password from config." unless [:password] raise ConfigItemMissing, "Missing server_name from config." unless [:server_name] raise ConfigItemMissing, "Missing client_id from config." unless [:client_id] raise ConfigItemMissing, "Missing endpoint_url from config." unless [:endpoint_url] raise ConfigItemMissing, "Missing authorization_url from config." unless [:authorization_url] raise ConfigItemMissing, "Missing realm from config." unless [:realm] if ![:token_store_file].instance_of?(String) || !::File.exist?([:token_store_file]) raise TokenStoreFileNotFound end @token_store_file = [:token_store_file] @user = [:user] @password = [:password] @server_name = [:server_name] @client_id = [:client_id] @endpoint_url = [:endpoint_url] Keycloak.auth_server_url = [:authorization_url] Keycloak.realm = [:realm] end |
.header ⇒ String
Gets, sets, and renews a Bearer access token as required and produces a Header string
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dina/authentication/authentication.rb', line 48 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 |