omniauth-auth0 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +20 -0
  5. data/.travis.yml +4 -1
  6. data/CHANGELOG.md +18 -1
  7. data/Gemfile +25 -3
  8. data/Guardfile +5 -0
  9. data/README.md +42 -26
  10. data/Rakefile +24 -4
  11. data/examples/sinatra/app.rb +14 -0
  12. data/examples/sinatra/config.ru +3 -0
  13. data/lib/omniauth-auth0.rb +2 -2
  14. data/lib/omniauth-auth0/version.rb +1 -1
  15. data/lib/omniauth/strategies/auth0.rb +74 -64
  16. data/omniauth-auth0.gemspec +12 -17
  17. data/spec/omniauth/strategies/auth0_spec.rb +240 -128
  18. data/spec/spec_helper.rb +46 -9
  19. metadata +23 -190
  20. data/examples/ruby-on-rails-webapp/.gitignore +0 -17
  21. data/examples/ruby-on-rails-webapp/Gemfile +0 -51
  22. data/examples/ruby-on-rails-webapp/README.md +0 -22
  23. data/examples/ruby-on-rails-webapp/README.rdoc +0 -28
  24. data/examples/ruby-on-rails-webapp/Rakefile +0 -6
  25. data/examples/ruby-on-rails-webapp/app/assets/images/.keep +0 -0
  26. data/examples/ruby-on-rails-webapp/app/assets/javascripts/application.js +0 -13
  27. data/examples/ruby-on-rails-webapp/app/assets/javascripts/home.js.erb +0 -10
  28. data/examples/ruby-on-rails-webapp/app/assets/stylesheets/application.css +0 -114
  29. data/examples/ruby-on-rails-webapp/app/controllers/application_controller.rb +0 -5
  30. data/examples/ruby-on-rails-webapp/app/controllers/auth0_controller.rb +0 -14
  31. data/examples/ruby-on-rails-webapp/app/controllers/concerns/.keep +0 -0
  32. data/examples/ruby-on-rails-webapp/app/controllers/dashboard_controller.rb +0 -5
  33. data/examples/ruby-on-rails-webapp/app/controllers/home_controller.rb +0 -5
  34. data/examples/ruby-on-rails-webapp/app/controllers/secured_controller.rb +0 -13
  35. data/examples/ruby-on-rails-webapp/app/helpers/application_helper.rb +0 -2
  36. data/examples/ruby-on-rails-webapp/app/helpers/callback_helper.rb +0 -2
  37. data/examples/ruby-on-rails-webapp/app/helpers/dashboard_helper.rb +0 -2
  38. data/examples/ruby-on-rails-webapp/app/helpers/home_helper.rb +0 -2
  39. data/examples/ruby-on-rails-webapp/app/mailers/.keep +0 -0
  40. data/examples/ruby-on-rails-webapp/app/models/.keep +0 -0
  41. data/examples/ruby-on-rails-webapp/app/models/concerns/.keep +0 -0
  42. data/examples/ruby-on-rails-webapp/app/views/auth0/failure.html.erb +0 -4
  43. data/examples/ruby-on-rails-webapp/app/views/dashboard/show.html.erb +0 -12
  44. data/examples/ruby-on-rails-webapp/app/views/home/show.html.erb +0 -14
  45. data/examples/ruby-on-rails-webapp/app/views/layouts/application.html.erb +0 -22
  46. data/examples/ruby-on-rails-webapp/bin/bundle +0 -3
  47. data/examples/ruby-on-rails-webapp/bin/rails +0 -4
  48. data/examples/ruby-on-rails-webapp/bin/rake +0 -4
  49. data/examples/ruby-on-rails-webapp/bin/spring +0 -18
  50. data/examples/ruby-on-rails-webapp/config.ru +0 -4
  51. data/examples/ruby-on-rails-webapp/config/application.rb +0 -32
  52. data/examples/ruby-on-rails-webapp/config/boot.rb +0 -4
  53. data/examples/ruby-on-rails-webapp/config/database.yml +0 -20
  54. data/examples/ruby-on-rails-webapp/config/environment.rb +0 -5
  55. data/examples/ruby-on-rails-webapp/config/environments/development.rb +0 -39
  56. data/examples/ruby-on-rails-webapp/config/environments/production.rb +0 -85
  57. data/examples/ruby-on-rails-webapp/config/environments/test.rb +0 -39
  58. data/examples/ruby-on-rails-webapp/config/initializers/01_dotenv.rb +0 -4
  59. data/examples/ruby-on-rails-webapp/config/initializers/auth0.rb +0 -9
  60. data/examples/ruby-on-rails-webapp/config/initializers/backtrace_silencers.rb +0 -7
  61. data/examples/ruby-on-rails-webapp/config/initializers/cookies_serializer.rb +0 -3
  62. data/examples/ruby-on-rails-webapp/config/initializers/filter_parameter_logging.rb +0 -4
  63. data/examples/ruby-on-rails-webapp/config/initializers/fix_ssl.rb +0 -15
  64. data/examples/ruby-on-rails-webapp/config/initializers/inflections.rb +0 -16
  65. data/examples/ruby-on-rails-webapp/config/initializers/mime_types.rb +0 -4
  66. data/examples/ruby-on-rails-webapp/config/initializers/session_store.rb +0 -3
  67. data/examples/ruby-on-rails-webapp/config/initializers/wrap_parameters.rb +0 -14
  68. data/examples/ruby-on-rails-webapp/config/locales/en.yml +0 -23
  69. data/examples/ruby-on-rails-webapp/config/routes.rb +0 -66
  70. data/examples/ruby-on-rails-webapp/config/secrets.yml +0 -35
  71. data/examples/ruby-on-rails-webapp/db/seeds.rb +0 -7
  72. data/examples/ruby-on-rails-webapp/lib/assets/.keep +0 -0
  73. data/examples/ruby-on-rails-webapp/lib/ca-bundle.crt +0 -3893
  74. data/examples/ruby-on-rails-webapp/lib/tasks/.keep +0 -0
  75. data/examples/ruby-on-rails-webapp/log/.keep +0 -0
  76. data/examples/ruby-on-rails-webapp/public/404.html +0 -67
  77. data/examples/ruby-on-rails-webapp/public/422.html +0 -67
  78. data/examples/ruby-on-rails-webapp/public/500.html +0 -66
  79. data/examples/ruby-on-rails-webapp/public/favicon.ico +0 -0
  80. data/examples/ruby-on-rails-webapp/public/robots.txt +0 -5
  81. data/examples/ruby-on-rails-webapp/test/controllers/.keep +0 -0
  82. data/examples/ruby-on-rails-webapp/test/controllers/callback_controller_test.rb +0 -14
  83. data/examples/ruby-on-rails-webapp/test/controllers/dashboard_controller_test.rb +0 -9
  84. data/examples/ruby-on-rails-webapp/test/controllers/home_controller_test.rb +0 -9
  85. data/examples/ruby-on-rails-webapp/test/fixtures/.keep +0 -0
  86. data/examples/ruby-on-rails-webapp/test/helpers/.keep +0 -0
  87. data/examples/ruby-on-rails-webapp/test/helpers/callback_helper_test.rb +0 -4
  88. data/examples/ruby-on-rails-webapp/test/helpers/dashboard_helper_test.rb +0 -4
  89. data/examples/ruby-on-rails-webapp/test/helpers/home_helper_test.rb +0 -4
  90. data/examples/ruby-on-rails-webapp/test/integration/.keep +0 -0
  91. data/examples/ruby-on-rails-webapp/test/mailers/.keep +0 -0
  92. data/examples/ruby-on-rails-webapp/test/models/.keep +0 -0
  93. data/examples/ruby-on-rails-webapp/test/test_helper.rb +0 -13
  94. data/examples/ruby-on-rails-webapp/vendor/assets/javascripts/.keep +0 -0
  95. data/examples/ruby-on-rails-webapp/vendor/assets/stylesheets/.keep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08baf1e899468bd2eb4eeaa08ddc3cf3cc4282df
4
- data.tar.gz: d7df08d4a6a624a68f48bb907b077d124e957877
3
+ metadata.gz: f42f79c741d55e309c3e99686af45d7f08ca5c92
4
+ data.tar.gz: 8b58d4f79437cb2fc1b2ee5f618ee30cef82bcea
5
5
  SHA512:
6
- metadata.gz: 9f3c3b20a7edf3fca038b36ca50821af43f17826b106d083f7f317aef913438c11932c02b60c13a03ff468a8cb12418655aa548ca6959663b554bab406dbd80d
7
- data.tar.gz: c9005d6fbf72f5fe14b7b20c5bb8ad2679f7fadd740251cc401bd3de7c95693ad8cb5dfdaab54154ebff3b12324e766129b1b44c6d274b929ce9104e3c1b2ab5
6
+ metadata.gz: 67e3c0c3fc88653047b8740dab4b89b06986b0ad943c09f67bfbec6bd4abba10c47f39e3a7cf287251a7d001804f756e0f1be80cc78874f0df1d540250310541
7
+ data.tar.gz: c284dd831da04571f6dedb6c9b0ab333fd40e474ea30bb433a3c6d28ee15dcddd6385c6f8c4ff0175da3b58073500973261231500e069b88fb2574db48c3723e
data/.gitignore CHANGED
@@ -1,4 +1,9 @@
1
1
  .ruby-version
2
2
  coverage
3
3
  Gemfile.lock
4
- *.gem
4
+ *.gem
5
+
6
+ .#*
7
+ .env
8
+ log/
9
+ tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format=progress
@@ -0,0 +1,20 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - 'Rakefile'
4
+ - '**/*.rake'
5
+ - 'spec/**/*.rb'
6
+ - 'spec/spec_helper.rb'
7
+ Metrics/MethodLength:
8
+ Exclude:
9
+ - 'Rakefile'
10
+ - '**/*.rake'
11
+ - 'spec/**/*.rb'
12
+ Metrics/AbcSize:
13
+ Exclude:
14
+ - 'Rakefile'
15
+ - '**/*.rake'
16
+ - 'spec/**/*.rb'
17
+ - 'spec/spec_helper.rb'
18
+ AllCops:
19
+ Exclude:
20
+ - 'omniauth-auth0.gemspec'
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
3
+ - 2.2.5
4
+ branches:
5
+ only:
6
+ - master
@@ -1,5 +1,22 @@
1
1
  # Change Log
2
2
 
3
+ ## [v2.0.0](https://github.com/auth0/omniauth-auth0/tree/v2.0.0) (2017-01-25)
4
+ [Full Changelog](https://github.com/auth0/omniauth-auth0/compare/v1.4.1...v2.0.0)
5
+
6
+ Updated library to handle OIDC conformant clients and OAuth2 features in Auth0.
7
+ This affects how the `credentials` and `info` attributes are populated since the payload of /oauth/token and /userinfo are differnt when using OAuth2/OIDC features.
8
+
9
+ The `credentials` hash will always have an `access_token` and might have a `refresh_token` (if it's allowed in your API settings in Auth0 dashboard and requested using `offline_access` scope) and an `id_token` (scope `openid` is needed for Auth0 to return it).
10
+
11
+ The `info` object will use the [OmniAuth schema](https://github.com/omniauth/omniauth/wiki/Auth-Hash-Schema#schema-10-and-later) after calling /userinfo:
12
+
13
+ - name: `name` attribute in userinfo response or `sub` if not available.
14
+ - email: `email` attribute in userinfo response.
15
+ - nickname: `nickname` attribute in userinfo response.
16
+ - image: `picture` attribute in userinfo response.
17
+
18
+ Also in `extra` will have in `raw_info` the full /userinfo response.
19
+
3
20
  ## [v1.4.1](https://github.com/auth0/omniauth-auth0/tree/v1.4.1) (2015-11-18)
4
21
  [Full Changelog](https://github.com/auth0/omniauth-auth0/compare/v1.4.0...v1.4.1)
5
22
 
@@ -21,4 +38,4 @@
21
38
 
22
39
 
23
40
 
24
- \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
41
+ \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
data/Gemfile CHANGED
@@ -1,4 +1,26 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in omniauth-auth0.gemspec
4
- gemspec
3
+ gemspec
4
+
5
+ gem 'gem-release'
6
+ gem 'rake'
7
+
8
+ group :development do
9
+ gem 'dotenv'
10
+ gem 'pry'
11
+ gem 'shotgun'
12
+ gem 'sinatra'
13
+ gem 'thin'
14
+ end
15
+
16
+ group :test do
17
+ gem 'guard-rspec', require: false
18
+ gem 'listen', '~> 3.1.5'
19
+ gem 'rack-test'
20
+ gem 'rspec', '~> 3.5'
21
+ gem 'rubocop', '>= 0.30', platforms: [
22
+ :ruby_19, :ruby_20, :ruby_21, :ruby_22
23
+ ]
24
+ gem 'simplecov'
25
+ gem 'webmock'
26
+ end
@@ -0,0 +1,5 @@
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ end
data/README.md CHANGED
@@ -14,7 +14,7 @@ gem 'omniauth-auth0'
14
14
 
15
15
  Then `bundle install`.
16
16
 
17
- ## Basic Usage
17
+ ## Usage
18
18
 
19
19
  ### Rails
20
20
 
@@ -24,10 +24,10 @@ Rails.application.config.middleware.use OmniAuth::Builder do
24
24
  end
25
25
  ```
26
26
 
27
- If you want to force an identity provider you can simply redirect to the Omniauth path like this:
27
+ Then to redirect to your tenant's hosted login page:
28
28
 
29
29
  ```ruby
30
- redirect_to '/auth/auth0?connection=CONNECTION_NAME'
30
+ redirect_to '/auth/auth0'
31
31
  ```
32
32
 
33
33
  ### Sinatra
@@ -38,20 +38,50 @@ use OmniAuth::Builder do
38
38
  end
39
39
  ```
40
40
 
41
- > Optional you can set the `:provider_ignores_state` passing a fourth parameter. By default it is true.
41
+ Then to redirect to your tenant's hosted login page:
42
42
 
43
- If you want to force to force an identity provider you can simply redirect to Omniauth path like this:
43
+ ```ruby
44
+ redirect to('/auth/auth0')
45
+ ```
46
+
47
+ > You can customize your hosted login page in your [Auth0 Dashboard](https://manage.auth0.com/#/login_page)
48
+
49
+ ### Auth parameters
50
+
51
+ To send additional parameters during login you can specify them when you register the provider
44
52
 
45
53
  ```ruby
46
- redirect to('/auth/auth0?connection=CONNECTION_NAME')
54
+ provider
55
+ :auth0,
56
+ ENV['AUTH0_CLIENT_ID'],
57
+ ENV['AUTH0_CLIENT_SECRET'],
58
+ ENV['AUTH0_DOMAIN'],
59
+ {
60
+ authorize_params: {
61
+ scope: 'openid read:users write:order',
62
+ audience: 'https://mydomain/api'
63
+ }
64
+ }
47
65
  ```
48
66
 
49
- ### Login widget
67
+ that will tell it to send those parameters on every Auth request.
50
68
 
51
- Integrate the widget in one of your pages as described [here](http://auth0.com/docs/lock) or use links as described in the same link.
69
+ Or you can do it for a specific Auth request by adding them in the query parameter of the redirect url:
70
+
71
+ ```ruby
72
+ redirect_to '/auth/auth0?connection=google-oauth2'
73
+ ```
52
74
 
53
75
  ### Auth Hash
54
76
 
77
+ Auth0 strategy will have the standard OmniAuth hash attributes:
78
+
79
+ - provider: the name of the strategy, in this case `auth0`
80
+ - uid: the user identifier
81
+ - info: the result of the call to /userinfo using OmniAuth standard attributes
82
+ - credentials: Auth0 tokens, at least will have an access_token but can eventually have refresh_token and/or id_token
83
+ - extra: Additional info obtained from calling /userinfo in the attribute `raw_info`
84
+
55
85
  ```ruby
56
86
  {
57
87
  :provider => 'auth0',
@@ -60,14 +90,13 @@ Integrate the widget in one of your pages as described [here](http://auth0.com/d
60
90
  :name => 'John Foo',
61
91
  :email => 'johnfoo@example.org',
62
92
  :nickname => 'john',
63
- :first_name => 'John',
64
- :last_name => 'Foo',
65
- :location => 'en',
66
93
  :image => 'https://example.org/john.jpg'
67
94
  },
68
95
  :credentials => {
69
96
  :token => 'XdDadllcas2134rdfdsI',
70
- :expires => 'false',
97
+ :expires_at => 1485373937,
98
+ :expires => true,
99
+ :refresh_token => 'aKNajdjfj123nBasd',
71
100
  :id_token => 'eyJhbGciOiJIUzI1NiIsImN0eSI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBGb28ifQ.lxAiy1rqve8ZHQEQVehUlP1sommPHVJDhgPgFPnDosg',
72
101
  :token_type => 'bearer',
73
102
  },
@@ -76,22 +105,9 @@ Integrate the widget in one of your pages as described [here](http://auth0.com/d
76
105
  :email => 'johnfoo@example.org',
77
106
  :email_verified => 'true',
78
107
  :name => 'John Foo',
79
- :given_name => 'John',
80
- :family_name => 'Foo',
81
108
  :picture => 'https://example.org/john.jpg',
82
- :gender => 'male',
83
- :locale => 'en',
84
- :clientID => 'nUBkskdaYdsaxK2n9',
85
109
  :user_id => 'google-oauth2|this-is-the-google-id',
86
110
  :nickname => 'john',
87
- :identities => [{
88
- :access_token => 'this-is-the-google-access-token',
89
- :provider => 'google-oauth2',
90
- :expires_in => '3599',
91
- :user_id => 'this-is-the-google-id',
92
- :connection => 'google-oauth2',
93
- :isSocial => 'true',
94
- }],
95
111
  :created_at: '2014-07-15T17:19:50.387Z'
96
112
  }
97
113
  }
@@ -120,7 +136,7 @@ If you have found a bug or if you have a feature request, please report them at
120
136
 
121
137
  ## Author
122
138
 
123
- [Auth0](auth0.com)
139
+ [Auth0](https://auth0.com)
124
140
 
125
141
  ## License
126
142
 
data/Rakefile CHANGED
@@ -1,10 +1,30 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
4
 
5
- desc "Run specs"
5
+ desc 'Run specs'
6
6
  RSpec::Core::RakeTask.new
7
7
 
8
+ begin
9
+ require 'rubocop/rake_task'
10
+ RuboCop::RakeTask.new
11
+ rescue LoadError
12
+ task :rubocop do
13
+ $stderr.puts 'Rubocop is disabled'
14
+ end
15
+ end
16
+
17
+ namespace :sinatra do
18
+ task :start do
19
+ system 'bundle exec shotgun' \
20
+ ' --server=thin --port=3000' \
21
+ ' examples/sinatra/config.ru'
22
+ end
23
+ end
24
+
8
25
  desc 'Run specs'
9
- task :default => :spec
10
- task :test => :spec
26
+ task default: [:spec, :rubocop]
27
+ task test: :spec
28
+ task :guard do
29
+ system 'bundle exec guard'
30
+ end
@@ -0,0 +1,14 @@
1
+ require 'sinatra'
2
+ require 'omniauth-auth0'
3
+ require 'dotenv/load'
4
+
5
+ use OmniAuth::Builder do
6
+ provider :auth0, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], ENV['DOMAIN']
7
+ end
8
+
9
+ enable :sessions
10
+ set :session_secret, ENV['SESSION_SECRET']
11
+
12
+ get '/' do
13
+ 'Auth0 OmniAuth Example for Sinatra'
14
+ end
@@ -0,0 +1,3 @@
1
+ require File.expand_path('app', File.dirname(__FILE__))
2
+
3
+ run Sinatra::Application
@@ -1,2 +1,2 @@
1
- require "omniauth-auth0/version"
2
- require "omniauth/strategies/auth0"
1
+ require 'omniauth-auth0/version' # rubocop:disable Style/FileName
2
+ require 'omniauth/strategies/auth0'
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Auth0
3
- VERSION = "1.4.2"
3
+ VERSION = '2.0.0'.freeze
4
4
  end
5
5
  end
@@ -1,94 +1,104 @@
1
- require "base64"
2
- require "omniauth-oauth2"
1
+ require 'base64'
2
+ require 'uri'
3
+ require 'omniauth-oauth2'
3
4
 
4
5
  module OmniAuth
5
6
  module Strategies
7
+ # Auth0 OmniAuth strategy
6
8
  class Auth0 < OmniAuth::Strategies::OAuth2
7
- PASSTHROUGHS = %w[
8
- connection
9
- redirect_uri
10
- ]
11
-
12
- option :name, "auth0"
13
- option :namespace, nil
14
- option :provider_ignores_state, true
15
- option :connection
9
+ option :name, 'auth0'
16
10
 
17
- option :client_options, {
18
- authorize_url: "/authorize",
19
- token_url: "/oauth/token",
20
- userinfo_url: "/userinfo"
21
- }
22
-
23
- args [:client_id, :client_secret, :namespace, :provider_ignores_state, :connection]
11
+ args [
12
+ :client_id,
13
+ :client_secret,
14
+ :domain
15
+ ]
24
16
 
25
- def initialize(app, *args, &block)
17
+ def client
18
+ options.client_options.site = domain_url
19
+ options.client_options.authorize_url = '/authorize'
20
+ options.client_options.token_url = '/oauth/token'
21
+ options.client_options.userinfo_url = '/userinfo'
26
22
  super
27
-
28
- if options[:namespace]
29
- @options.provider_ignores_state = args[3] unless args[3].nil?
30
- @options.connection = args[4] unless args[4].nil?
31
-
32
- @options.client_options.site =
33
- "https://#{options[:namespace]}"
34
- @options.client_options.authorize_url =
35
- "https://#{options[:namespace]}/authorize?#{self.class.client_info_querystring}"
36
- @options.client_options.token_url =
37
- "https://#{options[:namespace]}/oauth/token?#{self.class.client_info_querystring}"
38
- @options.client_options.userinfo_url =
39
- "https://#{options[:namespace]}/userinfo"
40
- elsif !options[:setup]
41
- fail(ArgumentError.new("Received wrong number of arguments. #{args.inspect}"))
42
- end
43
23
  end
44
24
 
45
- def authorize_params
46
- super.tap do |param|
47
- PASSTHROUGHS.each do |p|
48
- param[p.to_sym] = request.params[p] if request.params[p]
49
- end
50
- if @options.connection
51
- param[:connection] = @options.connection
52
- end
53
- end
54
- end
25
+ uid { raw_info['sub'] }
55
26
 
56
27
  credentials do
57
- hash = {'token' => access_token.token}
58
- hash.merge!('expires' => true)
28
+ hash = { 'token' => access_token.token }
29
+ hash['expires'] = true
59
30
  if access_token.params
60
- hash.merge!('id_token' => access_token.params['id_token'])
61
- hash.merge!('token_type' => access_token.params['token_type'])
62
- hash.merge!('refresh_token' => access_token.refresh_token) if access_token.refresh_token
31
+ hash['id_token'] = access_token.params['id_token']
32
+ hash['token_type'] = access_token.params['token_type']
33
+ hash['refresh_token'] = access_token.refresh_token
63
34
  end
64
35
  hash
65
36
  end
66
37
 
67
- uid { raw_info["user_id"] }
68
-
69
38
  extra do
70
- { :raw_info => raw_info }
39
+ {
40
+ raw_info: raw_info
41
+ }
71
42
  end
72
43
 
73
44
  info do
74
45
  {
75
- :name => raw_info["name"],
76
- :email => raw_info["email"],
77
- :nickname => raw_info["nickname"],
78
- :first_name => raw_info["given_name"],
79
- :last_name => raw_info["family_name"],
80
- :location => raw_info["locale"],
81
- :image => raw_info["picture"]
46
+ name: raw_info['name'] || raw_info['sub'],
47
+ nickname: raw_info['nickname'],
48
+ email: raw_info['email'],
49
+ image: raw_info['picture']
82
50
  }
83
51
  end
84
52
 
53
+ def authorize_params
54
+ params = super
55
+ params['auth0Client'] = client_info
56
+ params
57
+ end
58
+
59
+ def request_phase
60
+ if no_client_id?
61
+ fail!(:missing_client_id)
62
+ elsif no_client_secret?
63
+ fail!(:missing_client_secret)
64
+ elsif no_domain?
65
+ fail!(:missing_domain)
66
+ else
67
+ super
68
+ end
69
+ end
70
+
71
+ private
72
+
85
73
  def raw_info
86
- @raw_info ||= access_token.get(options.client_options.userinfo_url).parsed
74
+ userinfo_url = options.client_options.userinfo_url
75
+ @raw_info ||= access_token.get(userinfo_url).parsed
76
+ end
77
+
78
+ def no_client_id?
79
+ ['', nil].include?(options.client_id)
80
+ end
81
+
82
+ def no_client_secret?
83
+ ['', nil].include?(options.client_secret)
84
+ end
85
+
86
+ def no_domain?
87
+ ['', nil].include?(options.domain)
88
+ end
89
+
90
+ def domain_url
91
+ domain_url = URI(options.domain)
92
+ domain_url = URI("https://#{domain_url}") if domain_url.scheme.nil?
93
+ domain_url.to_s
87
94
  end
88
95
 
89
- def self.client_info_querystring
90
- client_info = JSON.dump({name: 'omniauth-auth0', version: OmniAuth::Auth0::VERSION})
91
- "auth0Client=" + Base64.urlsafe_encode64(client_info)
96
+ def client_info
97
+ client_info = JSON.dump(
98
+ name: 'omniauth-auth0',
99
+ version: OmniAuth::Auth0::VERSION
100
+ )
101
+ Base64.urlsafe_encode64(client_info)
92
102
  end
93
103
  end
94
104
  end