auth0 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b235b88935ed3273049d75b4b891ff2b1e0bd637
4
+ data.tar.gz: f8567a5d22322d22603b7e3c0248188786b743cf
5
+ SHA512:
6
+ metadata.gz: 26126f0981c005afa5e123cf0758a725d899b66d2537cf70cb068304b59d275051776bb6c50178888ea7098a906784d88fc8bfb5a2596418588a27e1d3b5dcf0
7
+ data.tar.gz: 8f87177b135bd95905f15f0b5b39a41898ea216dff7c788c6c68b2f06db0c5a9c6fe269114be3ebaef5c956996b4251f97fbc93267058e8d04cc6509783a0beb
@@ -0,0 +1,4 @@
1
+ .ruby-version
2
+ coverage
3
+ Gemfile.lock
4
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in auth0.gemspec
4
+ gemspec
@@ -0,0 +1,33 @@
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
+ ## Basic Usage
8
+
9
+ ### Rails
10
+
11
+ Rails.application.config.middleware.use OmniAuth::Builder do
12
+ provider :auth0, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], ENV['YOUR_NAMESPACE']
13
+ end
14
+
15
+ ### Sinatra
16
+
17
+ use OmniAuth::Builder do
18
+ provider :auth0, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], ENV['YOUR_NAMESPACE']
19
+ end
20
+
21
+ ## Connections
22
+
23
+ You can authorize many connections through Auth0. Link to
24
+
25
+ /auth/auth0?connection=<connection>
26
+
27
+ ## Documentation
28
+
29
+ For more information about [auth0](http://auth0.com) contact our [documentation page](http://docs.auth0.com/).
30
+
31
+ ## License
32
+
33
+ This client library is MIT licensed.
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc "Run specs"
6
+ RSpec::Core::RakeTask.new
7
+
8
+ desc 'Run specs'
9
+ task :default => :spec
@@ -0,0 +1,27 @@
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 = "auth0"
7
+ s.version = Auth0::VERSION
8
+ s.authors = ["Ezequiel Morito"]
9
+ s.email = ["me@ezequielmorito.com.ar"]
10
+ s.homepage = "https://github.com/auth0/ruby-auth0"
11
+ s.summary = %q{Ruby client library for the Auth0 platform.}
12
+ s.description = %q{Ruby client library for the Auth0 platform.}
13
+
14
+ s.rubyforge_project = "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_dependency 'omniauth', '~> 1.0'
22
+ s.add_dependency 'omniauth-oauth2', '~> 1.0'
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
+ end
@@ -0,0 +1,2 @@
1
+ require "auth0/version"
2
+ require "omniauth/strategies/auth0"
@@ -0,0 +1,3 @@
1
+ module Auth0
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,55 @@
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
+
14
+ args [:client_id, :client_secret, :namespace]
15
+
16
+ def initialize(app, *args, &block)
17
+ super
18
+ @options.client_options.site = "https://#{options[:namespace]}"
19
+ @options.client_options.authorize_url = "https://#{options[:namespace]}/authorize"
20
+ @options.client_options.token_url = "https://#{options[:namespace]}/oauth/token"
21
+ @options.client_options.userinfo_url = "https://#{options[:namespace]}/userinfo"
22
+ end
23
+
24
+ def authorize_params
25
+ super.tap do |param|
26
+ PASSTHROUGHS.each do |p|
27
+ param[p.to_sym] = request.params[p] if request.params[p]
28
+ end
29
+ end
30
+ end
31
+
32
+ uid { raw_info["user_id"] }
33
+
34
+ extra do
35
+ { :raw_info => raw_info }
36
+ end
37
+
38
+ info do
39
+ {
40
+ :name => raw_info["name"],
41
+ :email => raw_info["email"],
42
+ :nickname => raw_info["nickname"],
43
+ :first_name => raw_info["given_name"],
44
+ :last_name => raw_info["family_name"],
45
+ :location => raw_info["locale"],
46
+ :image => raw_info["picture"]
47
+ }
48
+ end
49
+
50
+ def raw_info
51
+ @raw_info ||= access_token.get(options.client_options.userinfo_url).parsed
52
+ end
53
+ end
54
+ end
55
+ 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
@@ -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,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auth0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ezequiel Morito
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Ruby client library for the Auth0 platform.
98
+ email:
99
+ - me@ezequielmorito.com.ar
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - README.md
107
+ - Rakefile
108
+ - auth0.gemspec
109
+ - lib/auth0.rb
110
+ - lib/auth0/version.rb
111
+ - lib/omniauth/strategies/auth0.rb
112
+ - spec/omniauth/strategies/auth0_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: https://github.com/auth0/ruby-auth0
115
+ licenses: []
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project: auth0
133
+ rubygems_version: 2.0.3
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Ruby client library for the Auth0 platform.
137
+ test_files:
138
+ - spec/omniauth/strategies/auth0_spec.rb
139
+ - spec/spec_helper.rb