omniauth-mailup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
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
+ .ruby-version
19
+ .ruby-gemset
20
+ .bashrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brian Getting
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # OmniAuth Mailup
2
+
3
+ MailUp OAuth2 Strategy for OmniAuth 1.0.
4
+
5
+ ## Installing
6
+
7
+ Add the strategy to your `Gemfile`:
8
+
9
+ gem 'omniauth-mailup'
10
+
11
+ Then `bundle install`.
12
+
13
+ ## Usage
14
+
15
+ `OmniAuth::Strategies::MailUp` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
16
+
17
+ ```ruby
18
+ use OmniAuth::Builder do
19
+ provider :mailup, ENV['MAILUP_CLIENT_ID'], ENV['MAILUP_CLIENT_SECRET']
20
+ end
21
+ ```
22
+
23
+ In Rails, you'll want to add to the middleware stack:
24
+
25
+ ```ruby
26
+ Rails.application.config.middleware.use OmniAuth::Builder do
27
+ provider :mailup, ENV['MAILUP_CLIENT_ID'], ENV['MAILUP_CLIENT_SECRET']
28
+ end
29
+ ```
30
+
31
+ ## Authentication Hash
32
+
33
+ Here's an example _Authentication Hash_ available in `request.env['omniauth.auth']`:
34
+
35
+ ```ruby
36
+ {
37
+ :provider => 'mailup',
38
+ :credentials => {
39
+ :token => 'adsf456lkj758klfdsg' # OAuth 2.0 access_token. Store and use to authenticate API requests.
40
+ }
41
+ }
42
+ ```
43
+
44
+ ## License
45
+
46
+ Copyright (c) 2013 by Brian Getting and MailUp Inc.
47
+
48
+ 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:
49
+
50
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
51
+
52
+ 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 @@
1
+ require "bundler/gem_tasks"
data/example/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'rack'
4
+ gem 'sinatra'
5
+ gem 'omniauth-mailup', :path => '../'
data/example/config.ru ADDED
@@ -0,0 +1,37 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-mailup'
4
+
5
+ class App < Sinatra::Base
6
+ get '/' do
7
+ <<-HTML
8
+ <div>
9
+ Your credentials are :
10
+ <ul>
11
+ <li>client id : #{ENV["MAILUP_CLIENT_ID"]}</li>
12
+ <li>secret key : #{ENV["MAILUP_CLIENT_SECRET"]}</li>
13
+ </ul>
14
+ </div>
15
+ <a href='/auth/mailup'>Sign in with MailUp</a>
16
+ HTML
17
+ end
18
+
19
+ get '/auth/:provider/callback' do
20
+ content_type 'text/plain'
21
+ token = request.env['omniauth.auth']['credentials']['token']
22
+ "Access token is #{token}".inspect rescue "No data"
23
+ end
24
+
25
+ get '/auth/failure' do
26
+ content_type 'text/plain'
27
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
28
+ end
29
+ end
30
+
31
+ use Rack::Session::Cookie, :secret => ENV['RACK_COOKIE_SECRET']
32
+
33
+ use OmniAuth::Builder do
34
+ provider :mailup, ENV["MAILUP_CLIENT_ID"], ENV["MAILUP_CLIENT_SECRET"]
35
+ end
36
+
37
+ run App.new
@@ -0,0 +1,35 @@
1
+ require 'omniauth-oauth2'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class MailUp < OmniAuth::Strategies::OAuth2
7
+
8
+ option :name, :mailup
9
+
10
+ option :client_options, {
11
+ :site => "https://services.mailup.com",
12
+ :authorize_url => "/Authorization/OAuth/LogOn",
13
+ :token_url => "/Authorization/OAuth/Token"
14
+ }
15
+
16
+ # TODO: Do we need this?
17
+ #option :provider_ignores_state, true
18
+
19
+ uid { raw_info["id"] }
20
+
21
+ info do
22
+ {
23
+ :email => raw_info["email"]
24
+ # TODO: Whatever other info we want to return
25
+ }
26
+ end
27
+
28
+ def raw_info
29
+ @raw_info ||= access_token.get('/API/v1/Console/User/Info.json').parsed
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ OmniAuth.config.add_camelization 'mailup', 'MailUp'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module MailUp
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-mailup/version"
2
+ require "omniauth/strategies/mailup"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-mailup/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omniauth-mailup"
8
+ gem.version = Omniauth::MailUp::VERSION
9
+ gem.authors = ["Brian Getting"]
10
+ gem.email = ["brian@tatem.ae"]
11
+ gem.description = %q{MailUp OAuth2 Strategy for OmniAuth 1.0.}
12
+ gem.summary = %q{OAuth2 Strategy for OmniAuth 1.0 for connecting to the MailUp REST API.}
13
+ gem.homepage = "https://github.com/tatemae-consultancy/omniauth-mailup"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.1.0'
21
+
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-mailup'
3
+ require 'base64'
4
+
5
+ describe OmniAuth::Strategies::MailUp do
6
+ before :each do
7
+ @request = double('Request')
8
+ @request.stub(:params) { {} }
9
+ @request.stub(:cookies) { {} }
10
+ end
11
+
12
+ subject do
13
+ OmniAuth::Strategies::MailUp.new(nil, @options || {}).tap do |strategy|
14
+ strategy.stub(:request) { @request }
15
+ end
16
+ end
17
+
18
+ describe '#client' do
19
+ it 'has correct MailUp api site' do
20
+ subject.options.client_options.site.should eq('https://services.mailup.com')
21
+ end
22
+
23
+ it 'has correct access token path' do
24
+ subject.options.client_options.token_url.should eq('/Authorization/OAuth/Token')
25
+ end
26
+
27
+ it 'has correct authorize url' do
28
+ subject.options.client_options.authorize_url.should eq('/Authorization/OAuth/LogOn')
29
+ end
30
+ end
31
+
32
+ describe '#callback_path' do
33
+ it 'should have the correct callback path' do
34
+ subject.callback_path.should eq('/auth/mailup/callback')
35
+ end
36
+ end
37
+
38
+ describe '#credentials' do
39
+ before :each do
40
+ @access_token = double('OAuth2::AccessToken')
41
+ @access_token.stub(:token)
42
+ @access_token.stub(:expires?)
43
+ @access_token.stub(:expires_at)
44
+ @access_token.stub(:refresh_token)
45
+ subject.stub(:access_token) { @access_token }
46
+ end
47
+
48
+ it 'returns a Hash' do
49
+ subject.credentials.should be_a(Hash)
50
+ end
51
+
52
+ it 'returns the token' do
53
+ @access_token.stub(:token) { '123' }
54
+ subject.credentials['token'].should eq('123')
55
+ end
56
+
57
+ it 'returns the expiry status' do
58
+ @access_token.stub(:expires?) { true }
59
+ subject.credentials['expires'].should eq(true)
60
+
61
+ @access_token.stub(:expires?) { false }
62
+ subject.credentials['expires'].should eq(false)
63
+ end
64
+ end
65
+ 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
@@ -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 token params passed in the :token_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ subject.token_params['foo'].should eq('bar')
28
+ subject.token_params['baz'].should eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :token_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ subject.token_params['scope'].should eq('bar')
34
+ subject.token_params['foo'].should eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-mailup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Getting
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: MailUp OAuth2 Strategy for OmniAuth 1.0.
63
+ email:
64
+ - brian@tatem.ae
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - example/Gemfile
75
+ - example/config.ru
76
+ - lib/omniauth-mailup.rb
77
+ - lib/omniauth-mailup/version.rb
78
+ - lib/omniauth/strategies/mailup.rb
79
+ - omniauth-mailup.gemspec
80
+ - spec/omniauth/strategies/mailup_spec.rb
81
+ - spec/spec_helper.rb
82
+ - spec/support/shared_examples.rb
83
+ homepage: https://github.com/tatemae-consultancy/omniauth-mailup
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.24
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: OAuth2 Strategy for OmniAuth 1.0 for connecting to the MailUp REST API.
107
+ test_files:
108
+ - spec/omniauth/strategies/mailup_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/support/shared_examples.rb