No commit activity in last 3 years
No release in over 3 years
Helper for handling COMPEON AccessToken's
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 5.0
~> 13.0

Runtime

~> 2.1
 Project Readme

Compeon::AccessToken

TODO: Delete this and the text above, and describe your gem

Installation

Add this line to your application's Gemfile:

gem 'compeon-access_token'

And then execute:

$ bundle

Or install it yourself as:

$ gem install compeon-access_token

Usage

Encode a token

token = Compeon::Token::Access.new(
  client_id: 'compeon-auth',
  role: 'customer',
  user_id: '123'
)

token.aud = 'audience'
token.iat = Time.now.to_i
token.exp = Time.now.to_i + 3600 # 1 Expiry time is required and must be in the future.
token.iss = 'issuer'
token.sub = 'subject'

token.encode(key: OpenSSL::PKey::RSA.new(private_key_string))
# => eyJhbGciOiJIUzI1NiIsInR5cC...

Decode a token

token = Compeon::Token::Access.decode(
  encoded_token: 'eyJhbGciOiJIUzI1NiIsInR5cC...',
  key: OpenSSL::PKey::RSA.new(private_key_string).public_key
)

token.client_id # => 'compeon-auth'
token.role # => 'customer'
token.user_id # => '123'
token.aud # => 'audience'
token.iss # => 'issuer'
# etc.

Decode a token and verify reserved claims

token = Compeon::Token::Access.decode(
  # The `exp` claim is validated by default and is not needed here
  claim_verifications: { aud: 'audience', iat: true, iss: 'issuer', sub: 'subject' },
  encoded_token: 'eyJhbGciOiJIUzI1NiIsInR5cC...',
  key: OpenSSL::PKey::RSA.new(private_key_string).public_key
)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/compeon/compeon-access_token.

License

The gem is available as open source under the terms of the MIT License.