Socket
Book a DemoInstallSign in
Socket

fridge

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fridge

1.0.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

Fridge

Gem Version Build Status Dependency Status

Token validation for distributed resource servers.

Installation

Add the following line to your application's Gemfile.

gem 'fridge'

And then run bundle install.

Usage

Configuration

ParameterDescriptionPossible Values
private_keyPrivate token signing keyA PEM-formatted key
public_keyPublic token verification key (the private key's complement)A PEM-formatted key
signing_algorithmAlgorithm to use for sigining and verificationRS512, RS256
validatorA lambda used to perform custom validation of tokensAny Proc

Resource servers must configure a public key corresponding to an authorization server, in order to verify tokens issued by that server. Authorization servers must configure a private key.

By default, public key-verified tokens are considered valid if and only iff they have not expired (i.e., expires_at > Time.now). However, some applications may want to perform additional validations. (For example, an authorization server may allow online revocation of tokens before their natural expiration, and need to check the current ). This is possible by configuring a custom validator:

Fridge.configure do |config|
  config.validator = lambda do |access_token|
    token = Token.find_by(id: access_token.id)
    token && !token.revoked?
  end
end

The validator will be called with a single argument, the Fridge::AccessToken instance.

Integrating with Fridge from a resource server

From any of your controllers, you may access the following methods:

  • current_token: The Fridge::AccessToken passed via Authorization header.
  • token_subject: The subject (:sub) of the current token.
  • token_scope: The scope (:scope) of the current token.
  • session_token: The Fridge::AccessToken stored in the user agent's cookies.
  • session_subject: The subject (:sub) of the current session token.

Integrating with Fridge from an authorization server

A Fridge access token may be constructed a la the following example:

access_token = Fridge::AccessToken.new(
  id: '0f1aa5ce-6e93-4812-b3fc-3b7f7b685991',
  subject: 'https://auth.aptible.com/users/e600a449-b308-4162-ac28-8a2769ad3f05',
  expires_at: 1.hour.from_now
)

The only required hash parameters are :subject and :expires_at. Additionally, you may specify :id, :scope and issuer. To set this token in a cookie that's readable across your entire domain, you may invoke the following command from any Rails controller:

store_session_cookie(access_token)

Contributing

  • Fork the project.
  • Commit your changes, with specs.
  • Ensure that your code passes specs (rake spec) and meets Aptible's Ruby style guide (rake rubocop).
  • Create a new pull request on GitHub.

MIT License, see LICENSE for details.

Copyright (c) 2019 Aptible and contributors.

FAQs

Package last updated on 06 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.