From 65723d3063498bf3bfdda2ce4429328c27709232 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Mon, 17 Apr 2017 13:11:44 +0200 Subject: [PATCH] Amazon SSO added --- Gemfile | 2 +- Gemfile.lock | 4 ++++ README.developer.md | 13 ++++++++++++- .../users/omniauth_callbacks_controller.rb | 4 ++++ app/models/user.rb | 3 ++- app/views/devise/sessions/new.slim | 1 + config/initializers/devise.rb | 1 + 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 5a78344..52a9509 100644 --- a/Gemfile +++ b/Gemfile @@ -117,7 +117,7 @@ gem "sprockets" # Authentication against Google, Facebook and others gem 'omniauth' -# gem 'omniauth-amazon' +gem 'omniauth-amazon' gem 'omniauth-google-oauth2' # gem 'omniauth-github' # gem 'omniauth-twitter' diff --git a/Gemfile.lock b/Gemfile.lock index 6711dfa..0de3c08 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -170,6 +170,9 @@ GEM omniauth (1.6.1) hashie (>= 3.4.6, < 3.6.0) rack (>= 1.6.2, < 3) + omniauth-amazon (1.0.1) + omniauth (~> 1.0) + omniauth-oauth2 (~> 1.1) omniauth-google-oauth2 (0.4.1) jwt (~> 1.5.2) multi_json (~> 1.3) @@ -326,6 +329,7 @@ DEPENDENCIES minitest-rails minitest-reporters omniauth + omniauth-amazon omniauth-google-oauth2 omniauth-openid paperclip diff --git a/README.developer.md b/README.developer.md index cbacf4a..412b8fb 100644 --- a/README.developer.md +++ b/README.developer.md @@ -9,7 +9,11 @@ Documentation on omniauth: https://github.com/omniauth/omniauth/wiki/List-of-Strategies https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview -## Google+ +List of strategies: + +https://github.com/omniauth/omniauth/wiki/List-of-Strategies + +## Google The client ID for the debshots and the private key must be set as environment variables before running the application: @@ -19,6 +23,13 @@ variables before running the application: ## Amazon +The client ID for the debshots and the secret must be set as environment +variables before running the application: + +* AMAZON_CLIENT_ID=… +* AMAZON_CLIENT_SECRET=… + + Client ID: amzn1.application-oa2-client.78d832919fc24456b0636762cf18efd9 diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index c1f6d98..0205691 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -15,6 +15,10 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController login_via 'Google' end + def amazon + login_via 'Amazon' + end + def login_via(provider_name) # You need to implement the method below in your model (e.g. app/models/user.rb) @user = User.from_omniauth(request.env["omniauth.auth"]) diff --git a/app/models/user.rb b/app/models/user.rb index 41fcb48..4e65929 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,7 +13,8 @@ class User < ApplicationRecord :omniauthable, :omniauth_providers => [ :launchpad, :stackexchange, - :google_oauth2 + :google_oauth2, + :amazon ] diff --git a/app/views/devise/sessions/new.slim b/app/views/devise/sessions/new.slim index 186ed6d..1e272fc 100644 --- a/app/views/devise/sessions/new.slim +++ b/app/views/devise/sessions/new.slim @@ -40,6 +40,7 @@ = link_to "Sign in with Launchpad", user_launchpad_omniauth_authorize_path = link_to "Sign in with StackExchange", user_stackexchange_omniauth_authorize_path = link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path += link_to "Sign in with Amazon", user_amazon_omniauth_authorize_path / div / = link_to image_tag('/images/sso/google.png'), user_google_oauth2_omniauth_authorize_path diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index cff1839..5aa9fc7 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -281,6 +281,7 @@ Devise.setup do |config| config.omniauth :open_id, name: :stackexchange, identifier: 'https://openid.stackexchange.com', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}} config.omniauth :open_id, name: :launchpad, identifier: 'https://login.ubuntu.com', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}} + config.omniauth :amazon, ENV['AMAZON_CLIENT_ID'], ENV['AMAZON_CLIENT_SECRET'], :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}} # client_options: {ssl: {ca_path: '/etc/ssl/certs'}} end