Class: BsJwt::Authentication
- Inherits:
-
Object
- Object
- BsJwt::Authentication
- Defined in:
- lib/bs_jwt/authentication.rb
Instance Attribute Summary collapse
-
#display_name ⇒ Object
Returns the value of attribute display_name.
-
#email ⇒ Object
Returns the value of attribute email.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#issued_at ⇒ Object
Returns the value of attribute issued_at.
-
#roles ⇒ Object
Returns the value of attribute roles.
-
#token ⇒ Object
Returns the value of attribute token.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#has_role?(role) ⇒ Boolean
rubocop:disable Naming/PredicateName.
-
#initialize(attributes = {}) ⇒ Authentication
constructor
A new instance of Authentication.
- #to_h ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Authentication
Returns a new instance of Authentication.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bs_jwt/authentication.rb', line 19 def initialize(attributes = {}) attributes = attributes.with_indifferent_access @roles = attributes[:roles] || [] @display_name = attributes[:display_name] @token = attributes[:token] @expires_at = attributes[:expires_at] @email = attributes[:email] @user_id = attributes[:user_id] @issued_at = attributes[:issued_at] end |
Instance Attribute Details
#display_name ⇒ Object
Returns the value of attribute display_name.
5 6 7 |
# File 'lib/bs_jwt/authentication.rb', line 5 def display_name @display_name end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/bs_jwt/authentication.rb', line 5 def email @email end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
5 6 7 |
# File 'lib/bs_jwt/authentication.rb', line 5 def expires_at @expires_at end |
#issued_at ⇒ Object
Returns the value of attribute issued_at.
5 6 7 |
# File 'lib/bs_jwt/authentication.rb', line 5 def issued_at @issued_at end |
#roles ⇒ Object
Returns the value of attribute roles.
5 6 7 |
# File 'lib/bs_jwt/authentication.rb', line 5 def roles @roles end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/bs_jwt/authentication.rb', line 5 def token @token end |
#user_id ⇒ Object
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/bs_jwt/authentication.rb', line 5 def user_id @user_id end |
Class Method Details
.from_jwt_payload(payload, jwt_token) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/bs_jwt/authentication.rb', line 7 def self.from_jwt_payload(payload, jwt_token) new( roles: payload['https://buddy.buddyandselly.com/roles'], display_name: payload['nickname'], token: jwt_token, expires_at: Time.at(payload['exp']), email: payload['name'], user_id: payload['sub'], issued_at: Time.at(payload['iat']) ) end |
Instance Method Details
#expired? ⇒ Boolean
34 35 36 |
# File 'lib/bs_jwt/authentication.rb', line 34 def expired? Time.now >= expires_at end |
#has_role?(role) ⇒ Boolean
rubocop:disable Naming/PredicateName
30 31 32 |
# File 'lib/bs_jwt/authentication.rb', line 30 def has_role?(role) # rubocop:disable Naming/PredicateName roles.include?(role) end |
#to_h ⇒ Object
38 39 40 |
# File 'lib/bs_jwt/authentication.rb', line 38 def to_h instance_values end |