Class: Warrant::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/warrant/models/session.rb

Class Method Summary collapse

Class Method Details

.create_authorization_session(params = {}, options = {}) ⇒ String

Create an Authorization Session for a given user

Parameters:

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

    a customizable set of options

Options Hash (params):

  • :user_id (String)

    Id of the user to create a session for.

  • :ttl (Integer)

    Number of seconds a session should live for. By default session tokens live for 24 hours and self service tokens live for 30 minutes.

Returns:

  • (String)

    Session token

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/warrant/models/session.rb', line 18

def self.create_authorization_session(params = {}, options = {})
    params = params.merge(type: "sess")
    res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/sessions"), params: Util.normalize_params(params), options: options)

    case res
    when Net::HTTPSuccess
        res_json = JSON.parse(res.body)
        res_json['token']
    else
        APIOperations.raise_error(res)
    end
end

.create_self_service_session(redirect_url, params = {}, options = {}) ⇒ String

Create a Self-Service Dashboard Session for a given user

Parameters:

  • redirect_url (String)

    URL to redirect to once self-service session is created

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

    a customizable set of options

Options Hash (params):

  • :user_id (String)

    Id of the user to create a session for.

  • :tenant_id (String)

    Id of the tenant to create a session for

  • :self_service_strategy (String)

    Determines whether a self-service token can be used for managing user roles and permissions (‘rbac`) or managing fine-grained user access to a particular object (`fgac`)

  • :ttl (Integer)

    Number of seconds a session should live for. By default session tokens live for 24 hours and self service tokens live for 30 minutes.

Returns:

  • (String)

    URL to the self service dashboard

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/warrant/models/session.rb', line 48

def self.create_self_service_session(redirect_url, params = {}, options = {})
    params = params.merge(type: "ssdash")
    res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/sessions"), params: Util.normalize_params(params), options: options)

    case res
    when Net::HTTPSuccess
        res_json = JSON.parse(res.body)
        "#{::Warrant.config.self_service_dash_url_base}/#{res_json['token']}?redirectUrl=#{redirect_url}"
    else
        APIOperations.raise_error(res)
    end
end