From c9a24e81e2c6ab334ddc7d62db54f07b4f67e937 Mon Sep 17 00:00:00 2001 From: benji Date: Thu, 19 Mar 2015 19:03:17 +0100 Subject: [PATCH] Add tab omniauth --- Gemfile | 2 +- Gemfile.lock | 18 +++++++++++++++++- config/initializers/tab.rb | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 config/initializers/tab.rb diff --git a/Gemfile b/Gemfile index 170b1a2..26435ea 100644 --- a/Gemfile +++ b/Gemfile @@ -75,4 +75,4 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw] gem 'coveralls', require: false -gem 'omniauth' +gem 'omniauth-oauth2' diff --git a/Gemfile.lock b/Gemfile.lock index 4c7f373..fb566ce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,6 +108,8 @@ GEM execjs (2.3.0) faker (1.4.2) i18n (~> 0.5) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) ffi (1.9.6-x64-mingw32) globalid (0.3.2) activesupport (>= 4.1.0) @@ -122,6 +124,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.2) + jwt (1.4.1) launchy (2.4.3) addressable (~> 2.3) loofah (2.0.1) @@ -132,6 +135,8 @@ GEM mini_portile (0.6.2) minitest (5.5.1) multi_json (1.10.1) + multi_xml (0.5.5) + multipart-post (2.0.0) mysql2 (0.3.17) net-scp (1.2.1) net-ssh (>= 2.6.5) @@ -141,9 +146,20 @@ GEM mini_portile (~> 0.6.0) nokogiri (1.6.6.2-x64-mingw32) mini_portile (~> 0.6.0) + oauth2 (1.0.0) + faraday (>= 0.8, < 0.10) + jwt (~> 1.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (~> 1.2) omniauth (1.2.2) hashie (>= 1.2, < 4) rack (~> 1.0) + omniauth-oauth2 (1.2.0) + faraday (>= 0.8, < 0.10) + multi_json (~> 1.3) + oauth2 (~> 1.0) + omniauth (~> 1.2) orm_adapter (0.5.0) paper_trail (4.0.0.beta2) activerecord (>= 3.0, < 6.0) @@ -267,7 +283,7 @@ DEPENDENCIES jquery-rails launchy mysql2 - omniauth + omniauth-oauth2 paper_trail (~> 4.0.0.beta) paperclip rails (= 4.2) diff --git a/config/initializers/tab.rb b/config/initializers/tab.rb new file mode 100644 index 0000000..1c73d89 --- /dev/null +++ b/config/initializers/tab.rb @@ -0,0 +1,39 @@ +require 'omniauth-oauth2' + +module OmniAuth + module Strategies + class Tab < OmniAuth::Strategies::OAuth2 + # Give your strategy a name. + option :name, "tab" + + # This is where you pass the options you would pass when + # initializing your consumer from the OAuth gem. + option :client_options, { + :site => "http://kelder.zeus.ugent.be/oauth/oauth2/authorize/" + } + + # These are called after authentication has succeeded. If + # possible, you should try to set the UID without making + # additional calls (if the user id is returned with the token + # or as a URI parameter). This may not be possible with all + # providers. + uid{ raw_info['id'] } + + info do + { + :name => raw_info['name'], + } + end + + extra do + { + 'raw_info' => raw_info + } + end + + def raw_info + @raw_info ||= access_token.get('/me').parsed + end + end + end +end