Class: MagentaSSO::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/magentasso.rb

Overview

A Magenta authentication request.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, nonce, scopes, callback_url) ⇒ Request

Returns a new instance of Request.



47
48
49
50
51
52
53
# File 'lib/magentasso.rb', line 47

def initialize(client_id, client_secret, nonce, scopes, callback_url)
  @client_id = client_id
  @client_secret = client_secret
  @nonce = nonce || SecureRandom.random_number(9_999_999)
  @scopes = [scopes].flatten
  @callback_url = callback_url
end

Instance Attribute Details

#callback_urlObject

Returns the value of attribute callback_url.



45
46
47
# File 'lib/magentasso.rb', line 45

def callback_url
  @callback_url
end

#client_idObject

Returns the value of attribute client_id.



45
46
47
# File 'lib/magentasso.rb', line 45

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



45
46
47
# File 'lib/magentasso.rb', line 45

def client_secret
  @client_secret
end

#nonceObject

Returns the value of attribute nonce.



45
46
47
# File 'lib/magentasso.rb', line 45

def nonce
  @nonce
end

#scopesObject

Returns the value of attribute scopes.



45
46
47
# File 'lib/magentasso.rb', line 45

def scopes
  @scopes
end

Class Method Details

.verify(payload, signature, client_secret) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/magentasso.rb', line 55

def self.verify(payload, signature, client_secret)
  payload = ::MagentaSSO.verify_and_decode(payload, signature, client_secret)

  new(
    payload["client_id"],
    client_secret,
    payload["nonce"],
    payload["scopes"],
    payload["callback_url"]
  )
end

Instance Method Details

#query_paramsObject



78
79
80
81
82
83
84
85
86
# File 'lib/magentasso.rb', line 78

def query_params
  payload, signature = sign

  {
    client: @client_id,
    payload: payload,
    signature: signature
  }
end

#signObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/magentasso.rb', line 67

def sign
  payload = {
    client_id: @client_id,
    nonce: @nonce,
    scopes: @scopes,
    callback_url: @callback_url
  }

  ::MagentaSSO.encode_and_sign(payload, @client_secret)
end