Module: Philiprehberger::JwtKit::TokenPair
- Defined in:
- lib/philiprehberger/jwt_kit/token_pair.rb
Overview
Generates and refreshes access/refresh token pairs.
Class Method Summary collapse
-
.generate(payload, config) ⇒ Array<String>
Generates an access token and refresh token pair.
-
.refresh(refresh_token, config) ⇒ String
Refreshes an access token using a valid refresh token.
Class Method Details
.generate(payload, config) ⇒ Array<String>
Generates an access token and refresh token pair.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/philiprehberger/jwt_kit/token_pair.rb', line 14 def generate(payload, config) access_token = Encoder.encode(payload, config) refresh_payload = payload.merge('type' => 'refresh') original_expiration = config.expiration config.expiration = config.refresh_expiration refresh_token = Encoder.encode(refresh_payload, config) config.expiration = original_expiration [access_token, refresh_token] end |
.refresh(refresh_token, config) ⇒ String
Refreshes an access token using a valid refresh token.
32 33 34 35 36 37 38 |
# File 'lib/philiprehberger/jwt_kit/token_pair.rb', line 32 def refresh(refresh_token, config) payload = Decoder.decode(refresh_token, config) raise InvalidToken, 'Token is not a refresh token' unless payload['type'] == 'refresh' new_payload = payload.except('exp', 'nbf', 'iat', 'jti', 'iss', 'aud', 'type') Encoder.encode(new_payload, config) end |