omniauth-fitcvut-oauth2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a338c1de42892ba2c19656b8b6dd9df3101fce9d
4
+ data.tar.gz: 0e6f0b87961d3e445ca0492080a46c57ee49c023
5
+ SHA512:
6
+ metadata.gz: 99ac933ab83282a1420d53bb4f5ae903aef562ce73a64074f78a4daac44e17d1a6247cb0c60cfa1703ca3e7873d6c8c585c5fe67e1a1d3c971091d09da9241d8
7
+ data.tar.gz: 359e1c77625baaddabf7d0f89f02a264d3bfb6f99c14edc0675336b62b8980fcd9600f696dbd837ab207732e2eb2890d1de9cc6b4c21cfe1cbac586f4b2d63c1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem 'omniauth-oauth2', :git => 'git://github.com/intridea/omniauth-oauth2.git'
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # OmniAuth CTU FIT
2
+
3
+ This gem contains the ČVUT/CTU FIT OAuth 2.0 strategy for OmniAuth 1.0.
4
+
5
+ ## Installing
6
+
7
+ Add to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'omniauth-fitcvut-oauth2', '~> 0.1.0'
11
+ ```
12
+
13
+ Then `bundle install`.
14
+
15
+ ## Basic Usage
16
+
17
+ use OmniAuth::Builder do
18
+ provider "fitcvut", ENV['FIT_APP_ID'], ENV['FIT_APP_SECRET']
19
+ end
20
+
21
+ ## Auth Hash
22
+
23
+ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
24
+ ```ruby
25
+ {
26
+ "provider" => "fitcvut",
27
+ "uid" => "username",
28
+ "info" => {
29
+ "name" => "username",
30
+ "email" => "username@fit.cvut.cz"
31
+ },
32
+ "credentials" => {
33
+ "token" => "0000000-0000-0000-0000-000000000000",
34
+ "refresh_token": "0000000-0000-0000-0000-000000000000",
35
+ "expires_at": 1442689203,
36
+ "expires": true
37
+ },
38
+ "extra" => {
39
+ "raw_info" => {
40
+ "client_id": "00000000-0000-0000-0000-000000000000",
41
+ "scope": [],
42
+ "audience": [],
43
+ "client_authorities": [
44
+ "ROLE_CLIENT"
45
+ ],
46
+ "expires_in": 7772621,
47
+ "user_id": "username",
48
+ "user_email": "username@fit.cvut.cz",
49
+ "user_authorities": [
50
+ "ROLE_R",
51
+ "ROLE_E",
52
+ "ROLE_L",
53
+ "ROLE_S",
54
+ "ROLE_U",
55
+ "ROLE__",
56
+ "ROLE_O"
57
+ ],
58
+ "client_only": false
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## License
65
+
66
+ Copyright (c) 2015 by Dominik Jancik based on
67
+ Copyright (c) 2011 by Lee Martin and SoundCloud
68
+
69
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
70
+
71
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/example/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'omniauth-fitcvut-oauth2', :path => '../'
data/example/config.ru ADDED
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-fitcvut-oauth2'
4
+
5
+ class App < Sinatra::Base
6
+ get '/' do
7
+ redirect '/auth/fitcvut_oauth2'
8
+ end
9
+
10
+ get '/auth/:provider/callback' do
11
+ content_type 'application/json'
12
+ MultiJson.encode(request.env)
13
+ end
14
+
15
+ get '/auth/failure' do
16
+ content_type 'application/json'
17
+ MultiJson.encode(request.env)
18
+ end
19
+ end
20
+
21
+ use Rack::Session::Cookie
22
+
23
+ use OmniAuth::Builder do
24
+ provider :fitcvut_oauth2, ENV['APP_ID'], ENV['APP_SECRET']
25
+ end
26
+
27
+ run App.new
@@ -0,0 +1 @@
1
+ require 'omniauth/fitcvut_oauth2'
@@ -0,0 +1 @@
1
+ require File.join('omniauth', 'strategies', 'fitcvut_oauth2')
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module FITCVUTOauth2
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class FITCVUTOauth2 < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = 'non-expiring'
7
+
8
+ option :name, "fitcvut_oauth2"
9
+
10
+ option :client_options, {
11
+ :site => 'https://auth.fit.cvut.cz',
12
+ :authorize_url => '/oauth/oauth/authorize',
13
+ :token_url => '/oauth/oauth/token'
14
+ }
15
+
16
+ uid{ raw_info['user_id'] }
17
+
18
+ info do
19
+ {
20
+ :name => raw_info['user_id'],
21
+ :email => raw_info['user_email']
22
+ }
23
+ end
24
+
25
+ extra do
26
+ {
27
+ 'raw_info' => raw_info
28
+ }
29
+ end
30
+
31
+ def raw_info
32
+ @raw_info ||= access_token.get("/oauth/api/v1/tokeninfo?token=#{access_token.token}").parsed
33
+ @raw_info
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ OmniAuth.config.add_camelization 'fitcvut_oauth2', 'FITCVUTOauth2'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/fitcvut_oauth2/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-fitcvut-oauth2'
7
+ s.version = OmniAuth::FITCVUTOauth2::VERSION
8
+ s.authors = ['Dominik Jančík']
9
+ s.email = %w(jancidom@fit.cvut.cz magnet.cz@gmail.com)
10
+ s.summary = 'CTU FIT OAuth2 OmniAuth 1.0 strategy'
11
+ s.homepage = 'https://github.com/MagNetCZ/omniauth-fitcvut-oauth2'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.3.0'
19
+
20
+ s.add_development_dependency 'rspec', '~> 3.3.0'
21
+ s.add_development_dependency 'rake'
22
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-fitcvut-oauth2'
3
+
4
+ describe OmniAuth::Strategies::FITCVUTOauth2 do
5
+ let(:request) do
6
+ double('request',
7
+ :params => {},
8
+ :cookies => {},
9
+ :env => {})
10
+ end
11
+
12
+ subject do
13
+ OmniAuth::Strategies::FITCVUTOauth2.new(nil, @options || {}).tap do |strategy|
14
+ strategy.stub(:request => request)
15
+ end
16
+ end
17
+
18
+ it_should_behave_like 'an oauth2 strategy'
19
+
20
+ describe '#client' do
21
+ it 'should have the correct FITCVUTOauth2 site' do
22
+ expect(subject.client.site).to eq('https://auth.fit.cvut.cz')
23
+ end
24
+
25
+ it 'should have the correct authorization url' do
26
+ expect(subject.client.options[:authorize_url]).to eq('/oauth/oauth/authorize')
27
+ end
28
+
29
+ it 'should have the correct token url' do
30
+ expect(subject.client.options[:token_url]).to eq('/oauth/oauth/token')
31
+ end
32
+ end
33
+
34
+ describe '#callback_path' do
35
+ it 'should have the correct callback path' do
36
+ expect(subject.callback_path).to eq('/auth/fitcvut_oauth2/callback')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
File without changes
@@ -0,0 +1,37 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ subject.client.options[:authorize_url].should == 'https://example.com'
7
+ end
8
+ end
9
+
10
+ # describe '#authorize_params' do
11
+ # it 'should include any authorize params passed in the :authorize_params option' do
12
+ # @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ # subject.authorize_params['foo'].should eq('bar')
14
+ # subject.authorize_params['baz'].should eq('zip')
15
+ # end
16
+
17
+ # it 'should include top-level options that are marked as :authorize_options' do
18
+ # @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ # subject.authorize_params['scope'].should eq('bar')
20
+ # subject.authorize_params['foo'].should eq('baz')
21
+ # end
22
+ # end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any authorize params passed in the :authorize_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ expect(subject.token_params['foo']).to eq('bar')
28
+ expect(subject.token_params['baz']).to eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :authorize_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ expect(subject.token_params['scope']).to eq('bar')
34
+ expect(subject.token_params['foo']).to eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-fitcvut-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dominik Jančík
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-21 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.3.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.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - jancidom@fit.cvut.cz
58
+ - magnet.cz@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - example/Gemfile
67
+ - example/config.ru
68
+ - lib/omniauth-fitcvut-oauth2.rb
69
+ - lib/omniauth/fitcvut_oauth2.rb
70
+ - lib/omniauth/fitcvut_oauth2/version.rb
71
+ - lib/omniauth/strategies/fitcvut_oauth2.rb
72
+ - omniauth-fitcvut-oauth2.gemspec
73
+ - spec/omniauth/strategies/fitcvut_spec.rb
74
+ - spec/spec_helper.rb
75
+ - spec/support/.keep
76
+ - spec/support/shared_examples.rb
77
+ homepage: https://github.com/MagNetCZ/omniauth-fitcvut-oauth2
78
+ licenses: []
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: CTU FIT OAuth2 OmniAuth 1.0 strategy
100
+ test_files: []