omniauth-protons 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +12 -0
- data/Guardfile +11 -0
- data/README.md +74 -0
- data/Rakefile +9 -0
- data/lib/omniauth/protons/version.rb +5 -0
- data/lib/omniauth/strategies/protons.rb +35 -0
- data/lib/omniauth-protons.rb +2 -0
- data/omniauth-protons.gemspec +20 -0
- data/spec/omniauth/strategies/oauth2_spec.rb +63 -0
- data/spec/spec_helper.rb +16 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb7d2b91479fac5929d8015acf9a940b946fda6f
|
4
|
+
data.tar.gz: ecf8c9547558b27681b88211e55048d6a10f3153
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a027f246273768fdc9ba64c8a085512726870a09555591cc1a9246b799570d3a4ec5ca0c3d9a4f6d0c7eba9cc5c3c62623925de50b60acffe147aa287a4d6fd2
|
7
|
+
data.tar.gz: bdf45ef976ced380e751f88df61a12de6c19c9a42054745ce2b0f4610f3f044e980222a90b98183e390e561aea82e0aa46d5b89abaedcc80d77ba41d5182c6a5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# OmniAuth OAuth2
|
2
|
+
|
3
|
+
This gem contains a generic OAuth2 strategy for OmniAuth. It is meant to
|
4
|
+
serve as a building block strategy for other strategies and not to be
|
5
|
+
used independently (since it has no inherent way to gather uid and user
|
6
|
+
info).
|
7
|
+
|
8
|
+
## Creating an OAuth2 Strategy
|
9
|
+
|
10
|
+
To create an OmniAuth OAuth2 strategy using this gem, you can simply
|
11
|
+
subclass it and add a few extra methods like so:
|
12
|
+
|
13
|
+
require 'omniauth-oauth2'
|
14
|
+
|
15
|
+
module OmniAuth
|
16
|
+
module Strategies
|
17
|
+
class SomeSite < OmniAuth::Strategies::OAuth2
|
18
|
+
# Give your strategy a name.
|
19
|
+
option :name, "some_site"
|
20
|
+
|
21
|
+
# This is where you pass the options you would pass when
|
22
|
+
# initializing your consumer from the OAuth gem.
|
23
|
+
option :client_options, {:site => "https://api.somesite.com"}
|
24
|
+
|
25
|
+
# These are called after authentication has succeeded. If
|
26
|
+
# possible, you should try to set the UID without making
|
27
|
+
# additional calls (if the user id is returned with the token
|
28
|
+
# or as a URI parameter). This may not be possible with all
|
29
|
+
# providers.
|
30
|
+
uid{ raw_info['id'] }
|
31
|
+
|
32
|
+
info do
|
33
|
+
{
|
34
|
+
:name => raw_info['name'],
|
35
|
+
:email => raw_info['email']
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
extra do
|
40
|
+
{
|
41
|
+
'raw_info' => raw_info
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def raw_info
|
46
|
+
@raw_info ||= access_token.get('/me').parsed
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
That's pretty much it!
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
Copyright (C) 2011 by Michael Bleigh and Intridea, Inc.
|
57
|
+
|
58
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
59
|
+
of this software and associated documentation files (the "Software"), to deal
|
60
|
+
in the Software without restriction, including without limitation the rights
|
61
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
62
|
+
copies of the Software, and to permit persons to whom the Software is
|
63
|
+
furnished to do so, subject to the following conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be included in
|
66
|
+
all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
69
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
70
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
71
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
72
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
73
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
74
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
# Authentication strategy for connecting with APIs constructed using
|
6
|
+
# the [OAuth 2.0 Specification](http://tools.ietf.org/html/draft-ietf-oauth-v2-10).
|
7
|
+
# You must generally register your application with the provider and
|
8
|
+
# utilize an application id and secret in order to authenticate using
|
9
|
+
# OAuth 2.0.
|
10
|
+
class Protons < OmniAuth::Strategies::OAuth2
|
11
|
+
# change the class name and the :name option to match your application name
|
12
|
+
option :name, :protons
|
13
|
+
|
14
|
+
option :client_options, {
|
15
|
+
:site => Rails.env.development? ? "http://8protons.dev" : "https://8protons.com",
|
16
|
+
:authorize_url => "/oauth/authorize"
|
17
|
+
}
|
18
|
+
|
19
|
+
uid { raw_info["id"] }
|
20
|
+
|
21
|
+
info do
|
22
|
+
{
|
23
|
+
:name => raw_info["display_name"],
|
24
|
+
:email => raw_info["email"],
|
25
|
+
:nickname => raw_info["username"]
|
26
|
+
# and anything else you want to return to your API consumers
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def raw_info
|
31
|
+
@raw_info ||= access_token.get('/api/users/me.json').parsed
|
32
|
+
end
|
33
|
+
end # Protons
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth/protons/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
|
6
|
+
|
7
|
+
gem.authors = ["Anthony Sekatski"]
|
8
|
+
gem.email = ["email@8protons.com"]
|
9
|
+
gem.description = %q{OAuth2 strategy for 8protons ID}
|
10
|
+
gem.summary = %q{OAuth2 strategy for 8protons ID}
|
11
|
+
gem.homepage = "https://github.com/intridea/omniauth-oauth2"
|
12
|
+
gem.license = "MIT"
|
13
|
+
|
14
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
gem.name = "omniauth-protons"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = OmniAuth::Protons::VERSION
|
20
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::OAuth2 do
|
4
|
+
def app; lambda{|env| [200, {}, ["Hello."]]} end
|
5
|
+
let(:fresh_strategy){ Class.new(OmniAuth::Strategies::OAuth2) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
OmniAuth.config.test_mode = true
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
OmniAuth.config.test_mode = false
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#client' do
|
16
|
+
subject{ fresh_strategy }
|
17
|
+
|
18
|
+
it 'should be initialized with symbolized client_options' do
|
19
|
+
instance = subject.new(app, :client_options => {'authorize_url' => 'https://example.com'})
|
20
|
+
instance.client.options[:authorize_url].should == 'https://example.com'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should set ssl options as connection options' do
|
24
|
+
instance = subject.new(app, :client_options => {'ssl' => {'ca_path' => 'foo'}})
|
25
|
+
instance.client.options[:connection_opts][:ssl] =~ {:ca_path => 'foo'}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#authorize_params' do
|
30
|
+
subject { fresh_strategy }
|
31
|
+
|
32
|
+
it 'should include any authorize params passed in the :authorize_params option' do
|
33
|
+
instance = subject.new('abc', 'def', :authorize_params => {:foo => 'bar', :baz => 'zip', :state => '123'})
|
34
|
+
instance.authorize_params.should == {'foo' => 'bar', 'baz' => 'zip', 'state' => '123'}
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should include top-level options that are marked as :authorize_options' do
|
38
|
+
instance = subject.new('abc', 'def', :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz', :authorize_params => {:state => '123'})
|
39
|
+
instance.authorize_params.should == {'scope' => 'bar', 'foo' => 'baz', 'state' => '123'}
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should include random state in the authorize params' do
|
43
|
+
instance = subject.new('abc', 'def')
|
44
|
+
instance.authorize_params.keys.should == ['state']
|
45
|
+
instance.session['omniauth.state'].should_not be_empty
|
46
|
+
instance.session['omniauth.state'].should == instance.authorize_params['state']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#token_params' do
|
51
|
+
subject { fresh_strategy }
|
52
|
+
|
53
|
+
it 'should include any authorize params passed in the :authorize_params option' do
|
54
|
+
instance = subject.new('abc', 'def', :token_params => {:foo => 'bar', :baz => 'zip'})
|
55
|
+
instance.token_params.should == {'foo' => 'bar', 'baz' => 'zip'}
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should include top-level options that are marked as :authorize_options' do
|
59
|
+
instance = subject.new('abc', 'def', :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz')
|
60
|
+
instance.token_params.should == {'scope' => 'bar', 'foo' => 'baz'}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
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 'omniauth-oauth2'
|
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
|
+
end
|
16
|
+
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-protons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anthony Sekatski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth-oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
description: OAuth2 strategy for 8protons ID
|
28
|
+
email:
|
29
|
+
- email@8protons.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- .rspec
|
36
|
+
- Gemfile
|
37
|
+
- Guardfile
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/omniauth-protons.rb
|
41
|
+
- lib/omniauth/protons/version.rb
|
42
|
+
- lib/omniauth/strategies/protons.rb
|
43
|
+
- omniauth-protons.gemspec
|
44
|
+
- spec/omniauth/strategies/oauth2_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
homepage: https://github.com/intridea/omniauth-oauth2
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.0.3
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: OAuth2 strategy for 8protons ID
|
70
|
+
test_files: []
|