Project

ask-auth

0.0
The project is in a healthy, maintained state
Env, file, Rails credentials, database, and OAuth providers. Zero external dependencies.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 5.25
~> 3.1
~> 13.0

Runtime

~> 0.2
 Project Readme

ask-auth

Gem Version

Credential resolution for the ask-rb ecosystem. A single API for resolving credentials across all ask-rb gems: service gems call Ask::Auth.resolve(:github_token) and never touch env vars, files, or OAuth flows directly. Zero external dependencies.

Installation

gem "ask-auth"

Quick Start

require "ask-auth"

token = Ask::Auth.resolve(:github_token)
# => "ghp_abc123..."

# Per-user credentials (Database, OAuth providers)
token = Ask::Auth.resolve(:openai_api_key, user: current_user)

resolve walks the provider chain in order and returns the first match, or raises Ask::Auth::MissingCredential. Multiple names can be given for fallbacks, and arrays of symbols resolve nested paths (e.g. resolve([:opencode, :api_key])).

Resolution chain

  1. Env: environment variables (ENV["GITHUB_TOKEN"])
  2. File: ~/.ask/credentials.yml
  3. RailsCredentials: Rails.application.credentials (when Rails is loaded)
  4. Database: ActiveRecord-backed per-user token storage (when ActiveRecord is loaded)
  5. OAuth: interactive PKCE flow (returns nil by default, requires explicit authorization)

Configuration

Ask::Auth.configure do |c|
  c.providers = [
    Ask::Auth::Providers::Env.new,
    Ask::Auth::Providers::File.new(path: "~/.myapp/creds.yml"),
    Ask::Auth::Providers::Database.new(model: AccessToken)
  ]
end

Any object responding to call(name, user:) can act as a provider. Once configured, the resolution chain is frozen and thread-safe.

Full documentation

The full ask-rb documentation lives at https://ask-rb.github.io/ask-docs. ask-auth in depth covers each provider, the OAuth flow, and error handling. API reference: https://ask-rb.github.io/ask-docs/reference/api.

Development

bundle install
bundle exec rake test

License

MIT