Class: Compeon::AccessToken
- Inherits:
-
Object
- Object
- Compeon::AccessToken
- Defined in:
- lib/compeon/access_token.rb,
lib/compeon/access_token/version.rb
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- VERSION =
'0.2.0'.freeze
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
- .parse(token) ⇒ Object
- .public_key ⇒ Object
- .public_key_string ⇒ Object
- .public_key_string=(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(role:, user_id:, kind:, client_id:, token:) ⇒ AccessToken
constructor
A new instance of AccessToken.
Constructor Details
#initialize(role:, user_id:, kind:, client_id:, token:) ⇒ AccessToken
Returns a new instance of AccessToken.
12 13 14 15 16 17 18 |
# File 'lib/compeon/access_token.rb', line 12 def initialize(role:, user_id:, kind:, client_id:, token:) @role = role @user_id = user_id @kind = kind @client_id = client_id @token = token end |
Class Attribute Details
.environment ⇒ Object
25 26 27 28 29 |
# File 'lib/compeon/access_token.rb', line 25 def environment @environment || ENV['ENVIRONMENT'] || raise("`#{self}.environment` or `ENV['ENVIRONMENT']` must be set") end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
20 21 22 |
# File 'lib/compeon/access_token.rb', line 20 def client_id @client_id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
20 21 22 |
# File 'lib/compeon/access_token.rb', line 20 def kind @kind end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
20 21 22 |
# File 'lib/compeon/access_token.rb', line 20 def role @role end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
20 21 22 |
# File 'lib/compeon/access_token.rb', line 20 def token @token end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
20 21 22 |
# File 'lib/compeon/access_token.rb', line 20 def user_id @user_id end |
Class Method Details
.parse(token) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/compeon/access_token.rb', line 31 def parse(token) data, _header = JWT.decode(token, public_key, false, algorithm: 'RS256') role = data.fetch('role') user_id = data.fetch('uid') kind = data.fetch('knd') client_id = data.fetch('cid') new(role: role, user_id: user_id, kind: kind, client_id: client_id, token: token) rescue JWT::DecodeError raise ParseError end |
.public_key ⇒ Object
44 45 46 |
# File 'lib/compeon/access_token.rb', line 44 def public_key @public_key ||= OpenSSL::PKey::RSA.new(public_key_string) end |
.public_key_string ⇒ Object
53 54 55 56 57 58 |
# File 'lib/compeon/access_token.rb', line 53 def public_key_string @public_key_string ||= begin env_subdomain = environment != 'production' ? ".#{environment}" : nil URI.parse("https://login#{env_subdomain}.compeon.de/public-key").read end end |
.public_key_string=(value) ⇒ Object
48 49 50 51 |
# File 'lib/compeon/access_token.rb', line 48 def public_key_string=(value) @public_key = nil @public_key_string = value end |