omniauth-reliefwatch 0.0.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: 515f56f947b617555708da96686e5f9d05773a0d
4
+ data.tar.gz: 8bf23c121a47659181fd1ad5f4c4274a9f68832c
5
+ SHA512:
6
+ metadata.gz: e7700766c8ec831253ca2034c68bfbeebe1e08a4c2bc8cd996471f8cc54b69561ba466c4d0530bc48234cf2b57462468917680db79551c03c95d711e3218ca0f
7
+ data.tar.gz: 3e0c803b2880f43e5c830cf3dc16a69e4f48de16a1bdeb6e099e82adcaa34190a287fd19f77ebd029c47ecd051ce8eedcbc114dd53921bedf9b31b6d8d076f1e
@@ -0,0 +1,22 @@
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
20
+ .ruby-*
21
+
22
+ info.markdown
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ group :test do
6
+ gem 'rspec', '~> 2.7'
7
+ gem 'guard'
8
+ gem 'guard-rspec', '4.2.8'
9
+ gem 'guard-livereload'
10
+ end
11
+
12
+ gemspec
@@ -0,0 +1,8 @@
1
+ rspec_opts = {
2
+ failed_mode: :focus
3
+ }
4
+
5
+ guard :rspec, cmd: "bundle exec rspec" do
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
8
+ end
@@ -0,0 +1,81 @@
1
+ OmniAuth::Reliefwatch
2
+ ==============
3
+
4
+ Reliefwatch OAuth2 Strategy for OmniAuth 1.0.
5
+
6
+ Supports the OAuth 2.0 server-side and client-side flows.
7
+
8
+ ### Adding omniauth-reliefwatch to your gemfile
9
+
10
+ Because you may want reference your own local reliefwatch app (which needs to be running at http://localhost:3000).
11
+
12
+ **Production**: add 'gem 'omniauth-reliefwatch'` to your gemfile
13
+
14
+ **Local**: `gem 'omniauth-reliefwatch', github: "reliefwatch/omniauth-reliefwatch", branch: 'local'` to your gemfile instead.
15
+
16
+
17
+ ## Creating an application
18
+
19
+ To be able to use OAuth on the Reliefwatch, you have to create an application. Go to [reliefwatch.org/oauth/applications](https://reliefwatch.com/oauth/applications)
20
+
21
+ Once you've added your application and your routes, you'll be able to see your Application ID and Secret, which you will need for omniauth.
22
+
23
+ **Note**: Callback url has to be an exact match - if your url is `http://localhost:3001/users/auth/reliefwatch/callback` you _must_ enter that exactly - `http://localhost:3001/users/auth/` will not work.
24
+
25
+
26
+ Check out **[API V1 Documentation](https://reliefwatch.com/documentation/api_v1)** to see what can be done with authenticated users.
27
+
28
+ ## Usage with rails and Devise
29
+
30
+ First add it to you Gemfile:
31
+
32
+ `gem 'omniauth-reliefwatch'`
33
+
34
+ Here's a quick example, adding the middleware to a Rails app in
35
+ `config/initializers/omniauth.rb`:
36
+
37
+ ```ruby
38
+ Rails.application.config.middleware.use OmniAuth::Builder do
39
+ provider :reliefwatch, ENV['RELIEFWATCH_APP_ID'], ENV['RELIEFWATCH_APP_SECRET']
40
+ end
41
+ ```
42
+
43
+ Your `RELIEFWATCH_APP_ID` and your `RELIEFWATCH_APP_SECRET` are both application specific. To create or view your applications go to [reliefwatch.com/oauth/applications](https://reliefwatch.com/oauth/applications).
44
+
45
+ Edit your routes.rb file to have:
46
+
47
+ `devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }`
48
+
49
+ And create a file called `omniauth_callbacks_controller.rb` which should have this inside:
50
+
51
+ ```ruby
52
+ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
53
+
54
+ def reliefwatch
55
+ # Delete the code inside of this method and write your own.
56
+ # The code below is to show you where to access the data.
57
+ raise request.env["omniauth.auth"].to_json
58
+ end
59
+ end
60
+ ```
61
+
62
+ ## Scopes
63
+
64
+ The default scope is `public` - which will be submitted unless you configure additional scopes. You can set scopes in the configuration with a space seperated list, e.g. for Devise
65
+
66
+ ```ruby
67
+ Devise.setup do |config|
68
+ config.omniauth :reliefwatch, ENV['RELIEFWATCH_APP_ID'], ENV['RELIEFWATCH_APP_SECRET'], scope: 'public`
69
+ end
70
+ ```
71
+
72
+
73
+
74
+ ## Credentials
75
+
76
+ The response will include a `uid` from Reliefwatch for the user and nothing else.
77
+
78
+
79
+ -----
80
+
81
+ Based on [omniauth-bike-index](https://github.com/bikeindex/omniauth-bike-index)
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,2 @@
1
+ require 'omniauth/reliefwatch/version'
2
+ require 'omniauth/strategies/reliefwatch'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Reliefwatch
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Reliefwatch < OmniAuth::Strategies::OAuth2
6
+ option :name, :reliefwatch
7
+ DEFAULT_SCOPE = 'public'
8
+ option :client_options, :site => 'https://reliefwatch.com',
9
+ :authorize_url => '/oauth/authorize'
10
+
11
+ uid { raw_info['id'] }
12
+
13
+ info do
14
+ prune!(
15
+ 'nickname' => raw_info['user']['username'],
16
+ 'email' => raw_info['user']['email'],
17
+ 'full_name' => raw_info['user']['full_name'],
18
+ )
19
+ end
20
+
21
+ extra do
22
+ hash = {}
23
+ hash['raw_info'] = raw_info unless skip_info?
24
+ prune! hash
25
+ end
26
+
27
+ def raw_info
28
+ @raw_info ||= access_token.get('/api/v1/me').parsed || {}
29
+ end
30
+
31
+ def request_phase
32
+ options[:authorize_params] = {
33
+ :scope => (options['scope'] || DEFAULT_SCOPE)
34
+ }
35
+
36
+ super
37
+ end
38
+
39
+ private
40
+
41
+ def prune!(hash)
42
+ hash.delete_if do |_, value|
43
+ prune!(value) if value.is_a?(Hash)
44
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/reliefwatch/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-reliefwatch'
7
+ s.version = OmniAuth::Reliefwatch::VERSION
8
+ s.authors = ['Seth Herr']
9
+ s.summary = 'Reliefwatch strategy for OmniAuth'
10
+ s.description = 'Reliefwatch strategy for OmniAuth v1.2'
11
+ s.homepage = 'https://github.com/Reliefwat/omniauth-reliefwatch'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").collect { |f| File.basename(f) }
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_runtime_dependency 'omniauth', '~> 1.2'
20
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
21
+
22
+ s.add_development_dependency 'dotenv', '~> 0'
23
+ s.add_development_dependency 'sinatra', '~> 0'
24
+ end
@@ -0,0 +1,49 @@
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-reliefwatch'
8
+
9
+ Dotenv.load
10
+
11
+ use Rack::Session::Cookie, :key => 'key',
12
+ :domain => 'localhost',
13
+ :path => '/',
14
+ :expire_after => 14_400,
15
+ :secret => 'secret'
16
+
17
+ use OmniAuth::Builder do
18
+ provider :reliefwatch, ENV['CLIENT_ID'], ENV['CLIENT_SECRET'], :scope => 'access_profile'
19
+ end
20
+
21
+ get '/' do
22
+ <<-HTML
23
+ <a href='/auth/reliefwatch'>Sign in with Reliefwatch</a>
24
+ HTML
25
+ end
26
+
27
+ get '/auth/failure' do
28
+ env['omniauth.error'].to_s
29
+ end
30
+
31
+ get '/auth/:name/callback' do
32
+ auth = request.env['omniauth.auth']
33
+
34
+ puts %Q(
35
+ >> UID
36
+ #{auth.uid.inspect}
37
+
38
+ >> ACCESS TOKEN
39
+ #{auth.credentials.token.inspect}
40
+
41
+ >> INFO
42
+ #{auth.info.inspect}
43
+ #
44
+ >> EXTRA
45
+ #{auth.extra.inspect}
46
+ )
47
+
48
+ 'Check logs for user information.'
49
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Reliefwatch do
4
+ subject do
5
+ @subject ||= begin
6
+ args = ['client_id', 'client_secret', @options || {}].compact
7
+ OmniAuth::Strategies::Reliefwatch.new(*args)
8
+ end
9
+ end
10
+
11
+ context 'client options' do
12
+ it 'has correct name' do
13
+ expect(subject.options.name).to eq(:reliefwatch)
14
+ end
15
+
16
+ it 'has correct site' do
17
+ expect(subject.options.client_options.site).to eq('https://reliefwatch.com')
18
+ end
19
+
20
+ it 'has correct authorize url' do
21
+ expect(subject.options.client_options.authorize_url).to eq('/oauth/authorize')
22
+ end
23
+
24
+ end
25
+
26
+ context 'figuring stuff out' do
27
+ it "gets log in" do
28
+ app = lambda{|env| [200, {}, ["Hello World."]]}
29
+ OmniAuth::Strategies::Developer.new(app).options.uid_field # => :email
30
+ OmniAuth::Strategies::Developer.new(app, :uid_field => :name).options.uid_field # => :name
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'omniauth'
6
+ require 'omniauth-reliefwatch'
7
+
8
+ RSpec.configure do |config|
9
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
10
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-reliefwatch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Seth Herr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-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: Reliefwatch strategy for OmniAuth v1.2
70
+ email:
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - Gemfile
77
+ - Guardfile
78
+ - README.md
79
+ - Rakefile
80
+ - lib/omniauth-reliefwatch.rb
81
+ - lib/omniauth/reliefwatch/version.rb
82
+ - lib/omniauth/strategies/reliefwatch.rb
83
+ - omniauth-reliefwatch.gemspec
84
+ - spec/app.rb
85
+ - spec/omniauth/strategies/reliefwatch_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: https://github.com/Reliefwat/omniauth-reliefwatch
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.8
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Reliefwatch strategy for OmniAuth
111
+ test_files:
112
+ - spec/app.rb
113
+ - spec/omniauth/strategies/reliefwatch_spec.rb
114
+ - spec/spec_helper.rb