Sha256: 98ab705921336b4462b10b3563fe7a32b2050c30776cffb181e08bfc26afe16c
Contents?: true
Size: 1.76 KB
Versions: 1
Compression:
Stored size: 1.76 KB
Contents
# OmniAuth Heroku [OmniAuth](https://github.com/intridea/omniauth) strategy for authenticating to Heroku. Heroku's support for OAuth is still private/experimental. ## Configuration OmniAuth works as a Rack middleware. Mount this Heroku adapter with: ```ruby use OmniAuth::Builder do provider :heroku, ENV['HEROKU_OAUTH_ID'], ENV['HEROKU_OAUTH_SECRET'] end ``` Your Heroku OAuth client should be set to receive callbacks on `/auth/heroku/callback`. ## Usage Initiate the OAuth flow sending users to `/auth/heroku`. Once the authorization flow is complete and the user is bounced back to your application, check `env["omniauth.auth"]["credentials"]`. It contains both a refresh token and an access token (identified just as `"token"`) to the account. We recommend using this access token together with [Heroku.rb](https://github.com/heroku/heroku.rb) to make API calls on behalf of the user. ## Example - Rails Under `config/initializers/omniauth.rb`: ```ruby Rails.application.config.middleware.use OmniAuth::Builder do provider :heroku, ENV['HEROKU_OAUTH_ID'], ENV['HEROKU_OAUTH_SECRET'] end ``` Then add to `config/routes.rb`: ```ruby Example::Application.routes.draw do get "login" => "sessions#new" get "/auth/:provider/callback" => "sessions#create" end ``` Controller support: ```ruby class SessionsController < ApplicationController def new redirect_to "/auth/heroku" end def create access_token = request.env['omniauth.auth']['credentials']['token'] heroku_api = Heroku::API.new(:api_key => access_token) @apps = api.get_apps.body end end ``` And view: ```erb <h1>Your Heroku apps:</h1> <ul> <% @apps.each do |app| %> <li><%= app["name"] %></li> <% end %> </ul> ``` ## Meta Released under the MIT license. Created by Pedro Belo.
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
omniauth-heroku-0.1.1 | README.md |