Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

basica

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basica

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

basica

Basic authentication library.

Description

Include the Basica module in your application, then call it by passing the env hash (should be available in every Rack based application) and a block. If the env hash contains the HTTP_AUTHORIZATION header, then the username and password will be passed to the block.

The result of the method call to basic_auth will be that of the block. If the HTTP_AUTHORIZATION header is not found, a RuntimeError is raised.

Example

First, an example of Basica in the wild:

require "basica"

include Basica

header = "Basic %s" % Base64.encode64("foo:bar")

env = { "HTTP_AUTHORIZATION" => header }

result = basic_auth(env) do |user, pass|
  user == "foo" && pass == "bar"
end

if result
  # The right credentials were provided.
end

Now an example of how to use it with Cuba and Shield:

Cuba.plugin Basica

Cuba.define do
  basic_auth(env) do |user, pass|
    login(User, user, pass)
  end

  on authenticated(User) do
    run Users
  end

  on default do
    res.status = 401
    res.headers["WWW-Authenticate"] = 'Basic realm="MyApp"'
    res.write "Unauthorized"
  end
end

Note that the previous example assumes you have already required Cuba, Shield, Basica, and that you have a User model defined.

Installation

Install it using rubygems.

$ gem install basica

FAQs

Package last updated on 22 Mar 2016

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc