omniauth-auth0 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +45 -0
- data/Rakefile +9 -0
- data/lib/auth0.rb +2 -0
- data/lib/auth0/version.rb +3 -0
- data/lib/omniauth/strategies/auth0.rb +58 -0
- data/omniauth-auth0.gemspec +29 -0
- data/spec/omniauth/strategies/auth0_spec.rb +149 -0
- data/spec/spec_helper.rb +17 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 323aa04766d3b6aade6324ceec94f515d6cecb83
|
4
|
+
data.tar.gz: d06a4c05bfb5c3908ca5487d19d62df33451b84b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57521c89903c9f219377b5a5d3fe39a76a011f6dd1d428033741d9108947776e428a11e1c48193b9dc46eea0f0dea4b37cacc0e0dfaf048722b12fd7de8d7c12
|
7
|
+
data.tar.gz: cd39dbc51d46ffbb02296ea6032d506248aa50ea1d6fc8ac99dba81dc8f4b9db26805fc64348212cbd132e49ab08902bd9c985e1e1c0503ee2bdf7376e732581
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# OmniAuth Auth0
|
2
|
+
|
3
|
+
This is the official OmniAuth strategy for authenticating to Auth0. To
|
4
|
+
use it, you'll need to sign up for an OAuth2 Application ID and Secret
|
5
|
+
on the [Auth0 Page](https://app.auth0.com).
|
6
|
+
|
7
|
+
## Installing
|
8
|
+
|
9
|
+
Add to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-auth0'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then `bundle install`.
|
16
|
+
|
17
|
+
## Basic Usage
|
18
|
+
|
19
|
+
### Rails
|
20
|
+
|
21
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
22
|
+
provider :auth0, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], ENV['YOUR_NAMESPACE']
|
23
|
+
end
|
24
|
+
|
25
|
+
### Sinatra
|
26
|
+
|
27
|
+
use OmniAuth::Builder do
|
28
|
+
provider :auth0, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], ENV['YOUR_NAMESPACE']
|
29
|
+
end
|
30
|
+
|
31
|
+
> Optional you can set the `:provider_ignores_state` passing a fourth parameter. By default it is true.
|
32
|
+
|
33
|
+
## Connections
|
34
|
+
|
35
|
+
You can authorize many connections through Auth0. Link to
|
36
|
+
|
37
|
+
/auth/auth0?connection=<connection>
|
38
|
+
|
39
|
+
## Documentation
|
40
|
+
|
41
|
+
For more information about [auth0](http://auth0.com) contact our [documentation page](http://docs.auth0.com/).
|
42
|
+
|
43
|
+
## License
|
44
|
+
|
45
|
+
This client library is MIT licensed.
|
data/Rakefile
ADDED
data/lib/auth0.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require "omniauth-oauth2"
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Auth0 < OmniAuth::Strategies::OAuth2
|
6
|
+
PASSTHROUGHS = %w[
|
7
|
+
connection
|
8
|
+
redirect_uri
|
9
|
+
]
|
10
|
+
|
11
|
+
option :name, "auth0"
|
12
|
+
option :namespace, nil
|
13
|
+
option :provider_ignores_state, true
|
14
|
+
|
15
|
+
args [:client_id, :client_secret, :namespace, :provider_ignores_state]
|
16
|
+
|
17
|
+
def initialize(app, *args, &block)
|
18
|
+
super
|
19
|
+
@options.provider_ignores_state = args[3] unless args[3].nil?
|
20
|
+
|
21
|
+
@options.client_options.site = "https://#{options[:namespace]}"
|
22
|
+
@options.client_options.authorize_url = "https://#{options[:namespace]}/authorize"
|
23
|
+
@options.client_options.token_url = "https://#{options[:namespace]}/oauth/token"
|
24
|
+
@options.client_options.userinfo_url = "https://#{options[:namespace]}/userinfo"
|
25
|
+
end
|
26
|
+
|
27
|
+
def authorize_params
|
28
|
+
super.tap do |param|
|
29
|
+
PASSTHROUGHS.each do |p|
|
30
|
+
param[p.to_sym] = request.params[p] if request.params[p]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
uid { raw_info["user_id"] }
|
36
|
+
|
37
|
+
extra do
|
38
|
+
{ :raw_info => raw_info }
|
39
|
+
end
|
40
|
+
|
41
|
+
info do
|
42
|
+
{
|
43
|
+
:name => raw_info["name"],
|
44
|
+
:email => raw_info["email"],
|
45
|
+
:nickname => raw_info["nickname"],
|
46
|
+
:first_name => raw_info["given_name"],
|
47
|
+
:last_name => raw_info["family_name"],
|
48
|
+
:location => raw_info["locale"],
|
49
|
+
:image => raw_info["picture"]
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def raw_info
|
54
|
+
@raw_info ||= access_token.get(options.client_options.userinfo_url).parsed
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "auth0/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-auth0"
|
7
|
+
s.version = Auth0::VERSION
|
8
|
+
s.authors = ["Auth0", "Ezequiel Morito", "Jose Romaniello"]
|
9
|
+
s.email = ["support@auth0.com"]
|
10
|
+
s.homepage = "https://github.com/auth0/omniauth-auth0"
|
11
|
+
s.summary = %q{Omniauth OAuth2 strategy for the Auth0 platform.}
|
12
|
+
s.description = %q{Omniauth OAuth2 strategy for the Auth0 platform.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "omniauth-auth0"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
|
22
|
+
|
23
|
+
s.add_development_dependency 'rspec', '~> 2.7'
|
24
|
+
s.add_development_dependency 'rack-test'
|
25
|
+
s.add_development_dependency 'simplecov'
|
26
|
+
s.add_development_dependency 'webmock'
|
27
|
+
|
28
|
+
s.license = 'MIT'
|
29
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::Auth0 do
|
4
|
+
let(:app){ Rack::Builder.new do |b|
|
5
|
+
b.use Rack::Session::Cookie, {:secret => "abc123"}
|
6
|
+
b.run lambda{|env| [200, {}, ['Not Found']]}
|
7
|
+
end.to_app }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
OmniAuth.config.test_mode = true
|
11
|
+
@request = double('Request')
|
12
|
+
@request.stub(:params) { {} }
|
13
|
+
@request.stub(:cookies) { {} }
|
14
|
+
@request.stub(:env) { {} }
|
15
|
+
|
16
|
+
@session = double('Session')
|
17
|
+
@session.stub(:delete).with('omniauth.state').and_return('state')
|
18
|
+
end
|
19
|
+
|
20
|
+
after do
|
21
|
+
OmniAuth.config.test_mode = false
|
22
|
+
end
|
23
|
+
|
24
|
+
subject do
|
25
|
+
OmniAuth::Strategies::Auth0.new(app,
|
26
|
+
"client_id", "client_secret", "tenny.auth0.com:3000").tap do |strategy|
|
27
|
+
strategy.stub(:request) { @request }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "initiation" do
|
32
|
+
it "uses the correct site" do
|
33
|
+
subject.options.client_options.site.
|
34
|
+
should == "https://tenny.auth0.com:3000"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "uses the correct authorize_url" do
|
38
|
+
subject.options.client_options.authorize_url.
|
39
|
+
should == "https://tenny.auth0.com:3000/authorize"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "uses the correct token_url" do
|
43
|
+
subject.options.client_options.token_url.
|
44
|
+
should == "https://tenny.auth0.com:3000/oauth/token"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "request phase" do
|
49
|
+
before(:each){ get '/auth/auth0' }
|
50
|
+
|
51
|
+
it "authenticate" do
|
52
|
+
expect(last_response.status).to eq(200)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "authorize params" do
|
56
|
+
subject.stub(:request) { double('Request', {:params => {
|
57
|
+
"connection" => "google-oauth2", "redirect_uri" => "redirect_uri" }, :env => {}}) }
|
58
|
+
subject.authorize_params.include?("connection").should == true
|
59
|
+
subject.authorize_params.include?("state").should == true
|
60
|
+
subject.authorize_params.include?("redirect_uri").should == true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "callback phase" do
|
65
|
+
before :each do
|
66
|
+
@raw_info = {
|
67
|
+
"_id" => "165dabb5140ee2cc66b5137912ccd760",
|
68
|
+
"email" => "user@mail.com",
|
69
|
+
"family_name" => "LastName",
|
70
|
+
"gender" => "male",
|
71
|
+
"given_name" => "FirstName",
|
72
|
+
"identities" => [
|
73
|
+
{
|
74
|
+
"access_token" => "ya29.AHES6ZRPK1Skc_rtB30Em_5RkZlKez3FkktcmJ_0RX5fIkCbkOCrXA",
|
75
|
+
"provider" => "google-oauth2",
|
76
|
+
"user_id" => "102835921788417079450",
|
77
|
+
"connection" => "google-oauth2",
|
78
|
+
"isSocial" => true
|
79
|
+
}
|
80
|
+
],
|
81
|
+
"locale" => "en",
|
82
|
+
"name" => "FirstName LastName",
|
83
|
+
"nickname" => "nick",
|
84
|
+
"picture" => "pic",
|
85
|
+
"user_id" => "google-oauth2|102835921788417079450"
|
86
|
+
}
|
87
|
+
subject.stub(:raw_info) { @raw_info }
|
88
|
+
end
|
89
|
+
|
90
|
+
context "info" do
|
91
|
+
it 'returns the uid (required)' do
|
92
|
+
subject.uid.should eq('google-oauth2|102835921788417079450')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns the name (required)' do
|
96
|
+
subject.info[:name].should eq('FirstName LastName')
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns the email' do
|
100
|
+
subject.info[:email].should eq('user@mail.com')
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns the nickname' do
|
104
|
+
subject.info[:nickname].should eq('nick')
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'returns the last name' do
|
108
|
+
subject.info[:last_name].should eq('LastName')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns the first name' do
|
112
|
+
subject.info[:first_name].should eq('FirstName')
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'returns the location' do
|
116
|
+
subject.info[:location].should eq('en')
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'returns the image' do
|
120
|
+
subject.info[:image].should eq('pic')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "get token" do
|
125
|
+
before :each do
|
126
|
+
@access_token = double('OAuth2::AccessToken')
|
127
|
+
@access_token.stub(:token)
|
128
|
+
@access_token.stub(:expires?)
|
129
|
+
@access_token.stub(:expires_at)
|
130
|
+
@access_token.stub(:refresh_token)
|
131
|
+
subject.stub(:access_token) { @access_token }
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'returns a Hash' do
|
135
|
+
subject.credentials.should be_a(Hash)
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'returns the token' do
|
139
|
+
@access_token.stub(:token) {
|
140
|
+
{
|
141
|
+
:access_token => "OTqSFa9zrh0VRGAZHH4QPJISCoynRwSy9FocUazuaU950EVcISsJo3pST11iTCiI",
|
142
|
+
:token_type => "bearer"
|
143
|
+
} }
|
144
|
+
subject.credentials['token'][:access_token].should eq('OTqSFa9zrh0VRGAZHH4QPJISCoynRwSy9FocUazuaU950EVcISsJo3pST11iTCiI')
|
145
|
+
subject.credentials['token'][:token_type].should eq('bearer')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'rspec'
|
6
|
+
require 'rack/test'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'omniauth'
|
9
|
+
require 'auth0'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include WebMock::API
|
13
|
+
config.include Rack::Test::Methods
|
14
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
15
|
+
config.color_enabled = true
|
16
|
+
config.formatter = 'documentation'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-auth0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Auth0
|
8
|
+
- Ezequiel Morito
|
9
|
+
- Jose Romaniello
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: omniauth-oauth2
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.1'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rspec
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '2.7'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.7'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rack-test
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: simplecov
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: webmock
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
description: Omniauth OAuth2 strategy for the Auth0 platform.
|
86
|
+
email:
|
87
|
+
- support@auth0.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/auth0.rb
|
97
|
+
- lib/auth0/version.rb
|
98
|
+
- lib/omniauth/strategies/auth0.rb
|
99
|
+
- omniauth-auth0.gemspec
|
100
|
+
- spec/omniauth/strategies/auth0_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/auth0/omniauth-auth0
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project: omniauth-auth0
|
122
|
+
rubygems_version: 2.0.3
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Omniauth OAuth2 strategy for the Auth0 platform.
|
126
|
+
test_files:
|
127
|
+
- spec/omniauth/strategies/auth0_spec.rb
|
128
|
+
- spec/spec_helper.rb
|