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

omniauth-chef-oauth2

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

omniauth-chef-oauth2

  • 1.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

omniauth-chef-oauth2

An OmniAuth OAuth2 strategy for Chef.

Usage

First, add it to your Gemfile:

gem 'omniauth-chef-oauth2'

.. then:

$ bundle install

To configure omniauth-chef-oauth2 in a Rails application, create an OmniAuth initializer file -- e.g., config/initializers/omniauth.rb -- then set your application key and secret:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :chef_oauth2, ENV['YOUR_APP_KEY'], ENV['YOUR_APP_SECRET']
end

Add a couple of handlers to routes.rb -- one for responding to authentication successes, one for failures:

YourRailsApp::Application.routes.draw do
  ...
  get '/auth/:provider/callback', to: 'sessions#create'
  get '/auth/failure', to: 'sessions#invalid'
end

On successful authentication, omniauth-chef-oauth2 will provide you with a Hash (as env['omniauth.auth']) representing the authenticated user:

class SessionsController < ApplicationController
  def create
    auth_hash = env['omniauth.auth']
    ...
  end

  def invalid
    #
  end
end

An successful auth_hash should look something like this:

{
  "provider" => "chef_oauth2",
  "uid" => "abrown",
  "info" => {
    "username" => "abrown",
    "first_name" => "Alton",
    "last_name" => "Brown",
    "email" => "alton@altonbrown.com",
    "public_key" => "-----BEGIN PUBLIC KEY-----..."
  },
  "credentials" => {
    "token" => "d3dbdb57",
    "refresh_token" => "3b508c06",
    "expires_at" => 1395955085,
    "expires" => true
  }
}

... where token contains the OAuth 2 access token you'll use to make authenticated API requests by passing a Bearer token in an Authorization header. For example:

GET /id/users/me
Authorization: Bearer d3dbdb57
Accept: application/json

Tests

$ bundle exec rspec

License

AuthorChristian Nunciato (cnunciato@getchef.com)
Copyright:Copyright (c) 2014 Chef Software, Inc.
License:Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

FAQs

Package last updated on 21 Jul 2021

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