Class: MagentaSSO::Response

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

Overview

A Magenta authentication response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, nonce, user_data, scope_data) ⇒ Response

Returns a new instance of Response.



93
94
95
96
97
98
99
# File 'lib/magentasso.rb', line 93

def initialize(client_id, client_secret, nonce, user_data, scope_data)
  @client_id = client_id
  @client_secret = client_secret
  @nonce = nonce
  @user_data = user_data
  @scope_data = scope_data
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



91
92
93
# File 'lib/magentasso.rb', line 91

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



91
92
93
# File 'lib/magentasso.rb', line 91

def client_secret
  @client_secret
end

#nonceObject

Returns the value of attribute nonce.



91
92
93
# File 'lib/magentasso.rb', line 91

def nonce
  @nonce
end

#scope_dataObject

Returns the value of attribute scope_data.



91
92
93
# File 'lib/magentasso.rb', line 91

def scope_data
  @scope_data
end

#user_dataObject

Returns the value of attribute user_data.



91
92
93
# File 'lib/magentasso.rb', line 91

def user_data
  @user_data
end

Class Method Details

.verify(payload, signature, client_secret) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/magentasso.rb', line 101

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["user_data"],
    payload["scope_data"]
  )
end

Instance Method Details

#email_addressObject



137
138
139
# File 'lib/magentasso.rb', line 137

def email_address
  @user_data&.[]("email")
end

#external_idObject



133
134
135
# File 'lib/magentasso.rb', line 133

def external_id
  @user_data&.[]("external_id")
end

#profile_nameObject



141
142
143
144
145
146
147
148
149
150
# File 'lib/magentasso.rb', line 141

def profile_name
  return nil unless @scope_data.key?("profile")

  return [@scope_data["profile"]["name_combined"], nil] if @scope_data["profile"].key?("name_combined")

  [
    @scope_data["profile"]["name_first"],
    @scope_data["profile"]["name_last"]
  ]
end

#query_paramsObject



124
125
126
127
128
129
130
131
# File 'lib/magentasso.rb', line 124

def query_params
  payload, signature = sign

  {
    payload: payload,
    signature: signature
  }
end

#signObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/magentasso.rb', line 113

def sign
  payload = {
    client_id: @client_id,
    nonce: @nonce,
    user_data: @user_data,
    scope_data: @scope_data
  }

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