omniauth-snoonet 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0bcdd10f2bf49c73cde78c0af48169c5f065c5c2
4
+ data.tar.gz: 114ef278b51c5b05e4354f0bb65e245c0b4548dd
5
+ SHA512:
6
+ metadata.gz: f44a96aa5fe0a8f87a08647a221bceca174014691e929709e680a4e594bf7ac472ac47165e8060dc6c9847baa6195297b57ea0b6b34691f2f1b1d8bb038060be
7
+ data.tar.gz: 6e0660827363850f76dfe8bf2e7070a8807e170e55b8cc20a6aeb60e34804545250c541dd0835f387158fc4efd8ddb46ed7651b7de042cd4c609c12a9f0102bc
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .env
19
+ .rspec
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ bundler_args: --without development
2
+ gemfile:
3
+ - Gemfile
4
+ language: ruby
5
+ rvm:
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - 2.0
9
+ - 2.1
10
+ - 2.2
11
+ - rbx-2
12
+ - ruby-head
13
+ - jruby-19mode
14
+ - jruby-head
15
+ matrix:
16
+ allow_failures:
17
+ - rvm: jruby-head
18
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ group :test do
6
+ gem 'coveralls', :require => false
7
+ gem 'rack-test'
8
+ gem 'rspec', '~> 3.1.0'
9
+ gem 'simplecov', :require => false
10
+ end
11
+
12
+ gemspec
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ omniauth-snoonet
2
+ ==============
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/omniauth-snoonet.png)](http://badge.fury.io/rb/omniauth-snoonet)
5
+ [![Build Status](https://travis-ci.org/snoonetIRC/omniauth-snoonet.png?branch=master)](https://travis-ci.org/snoonetIRC/omniauth-snoonet)
6
+
7
+ OmniAuth strategy to authenticate with Snoonet IRC services using OAuth 2.
8
+
9
+ ## Installation
10
+
11
+ Add to your `Gemfile`:
12
+
13
+ ```ruby
14
+ gem 'omniauth-snoonet'
15
+ ```
16
+
17
+ Then `bundle install`.
18
+
19
+
20
+ ## Usage
21
+
22
+ `OmniAuth::Strategies::Snoonet` is simply Rack middleware. Read the OmniAuth docs for instructions: https://github.com/intridea/omniauth.
23
+
24
+ An example what your `config/initializers/omniauth.rb` might look like:
25
+
26
+ ```ruby
27
+ Rails.application.config.middleware.use OmniAuth::Builder do
28
+ provider :snoonet, ENV['SNOONET_CLIENT_ID'], ENV['SNOONET_CLIENT_SECRET']
29
+ end
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ Currently, there is only one configuration option that needs to be set:
35
+
36
+ * `scope`: A comma-separated list of permissions you want to request from the user. The available permissions are as follows: `info`, `edit`. Default: `info`
37
+
38
+ ```ruby
39
+ Rails.application.config.middleware.use OmniAuth::Builder do
40
+ provider :snoonet, ENV['SNOONET_CLIENT_ID'], ENV['SNOONET_CLIENT_SECRET'], :scope => 'info,edit'
41
+ end
42
+
43
+ ```
44
+
45
+ ## Scope Details
46
+
47
+ * `info`: All NickServ info including the users email.
48
+ * `edit`: The ability to make changes to the users account.
49
+
50
+ ## Auth Hash
51
+
52
+ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
53
+
54
+ ```ruby
55
+ {
56
+ :provider => 'snoonet',
57
+ :uid => 'Nickname',
58
+ :info => {
59
+ :identifier => 'Nickname',
60
+ :registered => '2012-12-21 18:30:23',
61
+ :vhost => 'user/Nickname',
62
+ :lastquit => 'I quit.',
63
+ :options => ['Option', 'Other Option', 'Even Different Option'],
64
+ :email => 'john@example.com'
65
+ },
66
+ :credentials => {
67
+ :token => 'ABCDEF...',
68
+ :refresh_token => 'ABCDEF...',
69
+ :expires => true
70
+ },
71
+ :extra => {
72
+ :identifier => 'Nickname',
73
+ :info => {
74
+ :registered => {
75
+ :date => '2012-12-21 18:30:23',
76
+ :timezone_type => 3,
77
+ :timezone => 'UTC'
78
+ }
79
+ :vhost => 'user/Nickname',
80
+ :lastquit => 'I quit.',
81
+ :options => ['Option', 'Other Option', 'Even Different Option'],
82
+ :email => 'john@example.com'
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## Supported Ruby Versions
89
+ `omniauth-snoonet` is tested under 1.9.2, 1.9.3, 2.0.0, 2.1.0, MRI Ruby HEAD, JRuby (1.9 mode and HEAD), and Rubinius
90
+ (2.0 mode).
91
+
92
+ ## License
93
+
94
+ Copyright (c) 2014 by Snoonet
95
+
96
+ 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:
97
+
98
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
99
+
100
+ 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,8 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :test => :spec
7
+
8
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require 'omniauth/snoonet/version'
2
+ require 'omniauth/strategies/snoonet'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Snoonet
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Snoonet < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = 'info'
7
+
8
+ option :client_options, :site => 'https://oauth.snoonet.org',
9
+ :authorize_url => 'https://oauth.snoonet.org/authorize',
10
+ :token_url => 'https://oauth.snoonet.org/access_token'
11
+
12
+ uid { raw_info['identifier'] }
13
+
14
+ info do
15
+ {
16
+ :identifier => raw_info['identifier'],
17
+ :registered => raw_info['info']['registered']['date'],
18
+ :vhost => raw_info['info']['vhost'],
19
+ :lastquit => raw_info['info']['lastQuit'],
20
+ :options => raw_info['info']['options'],
21
+ :email => raw_info['info']['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('/api/v1/info').parsed || {}
33
+ end
34
+
35
+ def request_phase
36
+ options[:authorize_params] = {
37
+ :client_id => options['client_id'],
38
+ :response_type => 'code',
39
+ :scope => (options['scope'] || DEFAULT_SCOPE)
40
+ }
41
+
42
+ super
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/snoonet/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-snoonet'
7
+ s.version = OmniAuth::Snoonet::VERSION
8
+ s.authors = ['Snoonet']
9
+ s.email = ['operations@snoonet.org']
10
+ s.summary = 'Snoonet strategy for OmniAuth'
11
+ s.description = 'Snoonet strategy for OmniAuth'
12
+ s.homepage = 'https://github.com/snoonetIRC/omniauth-snoonet'
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_runtime_dependency 'omniauth', '~> 1.2'
21
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
22
+
23
+ s.add_development_dependency 'dotenv', '~> 0'
24
+ s.add_development_dependency 'sinatra', '~> 0'
25
+ end
data/spec/app.rb ADDED
@@ -0,0 +1,45 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'dotenv'
5
+ require 'sinatra'
6
+ require 'omniauth'
7
+ require 'omniauth-snoonet'
8
+
9
+ Dotenv.load
10
+
11
+ enable :sessions
12
+
13
+ use OmniAuth::Builder do
14
+ provider :snoonet, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'] # , :scope => 'profile'
15
+ end
16
+
17
+ get '/' do
18
+ <<-HTML
19
+ <a href='/auth/snoonet'>Sign in with Snoonet</a>
20
+ HTML
21
+ end
22
+
23
+ get '/auth/failure' do
24
+ env['omniauth.error'].to_s
25
+ end
26
+
27
+ get '/auth/:name/callback' do
28
+ auth = request.env['omniauth.auth']
29
+
30
+ puts %(
31
+ >> UID
32
+ #{auth.uid.inspect}
33
+
34
+ >> CREDENTIALS
35
+ #{auth.credentials.inspect}
36
+
37
+ >> INFO
38
+ #{auth.info.inspect}
39
+ #
40
+ >> EXTRA
41
+ #{auth.extra.inspect}
42
+ )
43
+
44
+ 'Check logs for user information.'
45
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Snoonet do
4
+ subject do
5
+ @subject ||= begin
6
+ @options ||= {}
7
+ args = ['client_id', 'client_secret', @options].compact
8
+ OmniAuth::Strategies::Snoonet.new(*args)
9
+ end
10
+ end
11
+
12
+ context 'client options' do
13
+ it 'should have correct name' do
14
+ expect(subject.options.name).to eq('snoonet')
15
+ end
16
+
17
+ it 'should have correct site' do
18
+ expect(subject.options.client_options.site).to eq('https://oauth.snoonet.org')
19
+ end
20
+
21
+ it 'should have correct authorize url' do
22
+ expect(subject.options.client_options.authorize_url).to eq('https://oauth.snoonet.org/authorize')
23
+ end
24
+
25
+ it 'should have correct access token url' do
26
+ expect(subject.options.client_options.token_url).to eq('https://oauth.snoonet.org/access_token')
27
+ end
28
+
29
+ it 'should indicate that the provider ignores the state parameter' do
30
+ expect(subject.options.provider_ignores_state).to eq false
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+
8
+ require 'omniauth'
9
+ require 'omniauth-snoonet'
10
+
11
+ RSpec.configure do |config|
12
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
13
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-snoonet
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Snoonet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-07 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.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
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.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
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
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
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
+ description: Snoonet strategy for OmniAuth
70
+ email:
71
+ - operations@snoonet.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - lib/omniauth-snoonet.rb
82
+ - lib/omniauth/snoonet/version.rb
83
+ - lib/omniauth/strategies/snoonet.rb
84
+ - omniauth-snoonet.gemspec
85
+ - spec/app.rb
86
+ - spec/omniauth/strategies/snoonet_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: https://github.com/snoonetIRC/omniauth-snoonet
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Snoonet strategy for OmniAuth
112
+ test_files:
113
+ - spec/app.rb
114
+ - spec/omniauth/strategies/snoonet_spec.rb
115
+ - spec/spec_helper.rb