omniauth-underarmour 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +15 -0
- data/LICENSE.md +20 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/example/Gemfile +6 -0
- data/example/example.rb +18 -0
- data/lib/omniauth-underarmour.rb +2 -0
- data/lib/omniauth-underarmour/version.rb +5 -0
- data/lib/omniauth/strategies/underarmour.rb +65 -0
- data/omniauth-underarmour.gemspec +21 -0
- data/spec/omniauth/strategies/underarmour_spec.rb +124 -0
- data/spec/spec_helper.rb +14 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50192e977ccc1d554390c05c7c91c51b79114b2f
|
4
|
+
data.tar.gz: 6e7ff7545e8ca0a540e141211ba49a9ffdd76a1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 61bf034d3c57692eafb1e8454d9468f1b2035f9cdfb11976b281fb1a646b4c77950d93d13b904d24ccc67784cfec790c991c82c8872e2e874c0ee8f3a3cdff37
|
7
|
+
data.tar.gz: 60a89b13ce874757230f5c81d9efcdfba21d2a1898b308c3ed761c903d2b6c6e59488e063d09f5d8a4f1ca89c9ded859b5c538685d2a5e7fc81a1aa2d0f66816
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Sergey Baev, https://github.com/tinbka
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# OmniAuth UnderArmour Strategy
|
2
|
+
|
3
|
+
This gem is an OmniAuth 1.0+ Strategy for the [UnderArmour API](https://developer.underarmour.com/docs/v71_OAuth_2_Intro).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add the strategy to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-underarmour'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then integrate the strategy into your middleware:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
use OmniAuth::Builder do
|
17
|
+
provider :underarmour, 'consumer_key', 'consumer_secret'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
In Rails, create a new file under config/initializers called omniauth.rb to plug the strategy into your middleware stack.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
25
|
+
provider :underarmour, 'consumer_key', 'consumer_secret'
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
For usage with Devise go to [Facebook Example at Devise wiki](https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview#facebook-example).
|
30
|
+
|
31
|
+
To register your application with Fitbit and obtain a consumer key and secret, go to the [UnderArmour Mashery ID registration](https://developer.underarmour.com/member/register).
|
32
|
+
|
33
|
+
For additional information about OmniAuth, visit [OmniAuth wiki](https://github.com/intridea/omniauth/wiki).
|
34
|
+
|
35
|
+
For a short tutorial on how to use OmniAuth in your Rails application, visit [this tutsplus.com tutorial](http://net.tutsplus.com/tutorials/ruby/how-to-use-omniauth-to-authenticate-your-users/).
|
data/Rakefile
ADDED
data/example/Gemfile
ADDED
data/example/example.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'omniauth-underarmour'
|
3
|
+
|
4
|
+
use Rack::Session::Cookie
|
5
|
+
use OmniAuth::Builder do
|
6
|
+
provider :underarmour, '', '', { :redirect_uri => 'http://localhost:4567/auth/underarmour/callback' }
|
7
|
+
end
|
8
|
+
|
9
|
+
get '/' do
|
10
|
+
<<-HTML
|
11
|
+
<a href='/auth/underarmour'>Sign in with Fitbit</a>
|
12
|
+
HTML
|
13
|
+
end
|
14
|
+
|
15
|
+
get '/auth/fitbit/callback' do
|
16
|
+
# Do whatever you want with the data
|
17
|
+
MultiJson.encode(request.env['omniauth.auth'])
|
18
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Underarmour < OmniAuth::Strategies::OAuth2
|
6
|
+
|
7
|
+
option :name, "underarmour"
|
8
|
+
|
9
|
+
option :client_options, {
|
10
|
+
:site => 'https://www.mapmyfitness.com',
|
11
|
+
:authorize_url => '/v7.1/oauth2/uacf/authorize/',
|
12
|
+
:token_url => '/v7.1/oauth2/access_token/'
|
13
|
+
}
|
14
|
+
|
15
|
+
option :response_type, 'code'
|
16
|
+
option :authorize_options, %i(response_type redirect_uri)
|
17
|
+
|
18
|
+
def build_access_token
|
19
|
+
options.token_params.merge!(:headers => {'Authorization' => basic_auth_header })
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def basic_auth_header
|
24
|
+
"Basic " + Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def query_string
|
28
|
+
# Using state and code params in the callback_url causes a mismatch with
|
29
|
+
# the value set in the fitbit application configuration, so we're skipping them
|
30
|
+
''
|
31
|
+
end
|
32
|
+
|
33
|
+
uid do
|
34
|
+
access_token.params['user_id']
|
35
|
+
end
|
36
|
+
|
37
|
+
info do
|
38
|
+
{
|
39
|
+
:name => "#{raw_info['first_name']} #{raw_info['last_name']}",
|
40
|
+
:first_name => raw_info['first_name'],
|
41
|
+
:last_name => raw_info['last_name'],
|
42
|
+
:nickname => raw_info['username'],
|
43
|
+
:gender => raw_info['gender'],
|
44
|
+
:city => raw_info['locality'],
|
45
|
+
:state => raw_info['region'],
|
46
|
+
:country => raw_info['country'],
|
47
|
+
:birthdate => raw_info['birthdate'] && !raw_info['birthdate'].empty? ? Date.parse(raw_info['birthdate']) : nil,
|
48
|
+
:date_joined => Date.parse(raw_info['date_joined']),
|
49
|
+
:locale => raw_info['preferred_language'],
|
50
|
+
:timezone => raw_info['time_zone']
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
extra do
|
55
|
+
{
|
56
|
+
:raw_info => raw_info
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def raw_info
|
61
|
+
@raw_info ||= MultiJson.load(access_token.request(:get, 'https://api.ua.com/v7.1/user/self/', headers: {'api-key' => options[:client_id]}).body)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-underarmour/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-underarmour"
|
7
|
+
s.version = OmniAuth::Underarmour::VERSION
|
8
|
+
s.authors = ["Sergey Baev"]
|
9
|
+
s.email = ["tinbka@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/tinbka/omniauth-underarmour"
|
11
|
+
s.summary = %q{OmniAuth OAuth2 strategy for UnderArmour}
|
12
|
+
s.description = %q{OmniAuth OAuth2 strategy for UnderArmour}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split($\)
|
15
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.4'
|
20
|
+
s.add_runtime_dependency 'multi_xml'
|
21
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "OmniAuth::Strategies::Underarmour" do
|
4
|
+
subject do
|
5
|
+
OmniAuth::Strategies::Underarmour.new(nil, @options || {})
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'response_type' do
|
9
|
+
it 'includes :code' do
|
10
|
+
expect(subject.options["response_type"]).to include('code')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'authorize_options' do
|
15
|
+
it 'includes :response_type' do
|
16
|
+
expect(subject.options["authorize_options"]).to include(:response_type)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'includes :redirect_uri' do
|
20
|
+
expect(subject.options["authorize_options"]).to include(:redirect_uri)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'client options' do
|
25
|
+
it 'has correct OAuth endpoint' do
|
26
|
+
expect(subject.options.client_options.site).to eq('https://www.mapmyfitness.com')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'has correct authorize url' do
|
30
|
+
expect(subject.options.client_options.authorize_url).to eq('/v7.1/oauth2/uacf/authorize/')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'has correct token url' do
|
34
|
+
expect(subject.options.client_options.token_url).to eq('/v7.1/oauth2/access_token/')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'auth header' do
|
39
|
+
before :each do
|
40
|
+
subject.options.client_id = 'testclientid'
|
41
|
+
subject.options.client_secret = 'testclientsecret'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns the correct authorization header value' do
|
45
|
+
expect(subject.basic_auth_header).to eq('Basic ' + Base64.strict_encode64("testclientid:testclientsecret"))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'uid' do
|
50
|
+
before :each do
|
51
|
+
access_token = double('access_token')
|
52
|
+
allow(access_token).to receive('params') { { 'user_id' => '123ABC' } }
|
53
|
+
allow(subject).to receive(:access_token) { access_token }
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns the correct id from raw_info' do
|
57
|
+
expect(subject.uid).to eq('123ABC')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'info' do
|
62
|
+
before :each do
|
63
|
+
allow(subject).to receive(:raw_info) {
|
64
|
+
{
|
65
|
+
"date_joined" => "2010-01-01",
|
66
|
+
"first_name" => "John",
|
67
|
+
"last_name" => "Doe",
|
68
|
+
"gender" => "M",
|
69
|
+
"last_initial" => "D",
|
70
|
+
"last_login" => "2016-01-01",
|
71
|
+
"locality" => "Kansas City",
|
72
|
+
"region" => "MO",
|
73
|
+
"country" => "US",
|
74
|
+
"time_zone" => "America/Chicago",
|
75
|
+
"username" => "johnnie",
|
76
|
+
"preferred_language" => "en-US",
|
77
|
+
"birthdate" => "2016-01-01"
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'returns the correct name from raw_info' do
|
83
|
+
expect(subject.info[:name]).to eq("John Doe")
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns the correct nickname from raw_info' do
|
87
|
+
expect(subject.info[:nickname]).to eq("johnnie")
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns the correct gender from raw_info' do
|
91
|
+
expect(subject.info[:gender]).to eq("M")
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns the correct city from raw_info' do
|
95
|
+
expect(subject.info[:city]).to eq("Kansas City")
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'returns the correct state from raw_info' do
|
99
|
+
expect(subject.info[:state]).to eq("MO")
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'returns the correct locale from raw_info' do
|
103
|
+
expect(subject.info[:locale]).to eq("en-US")
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns the correct birthdate from raw_info' do
|
107
|
+
expect(subject.info[:birthdate]).to eq(Date.parse("2016-01-01"))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'birthdate is empty' do
|
112
|
+
before :each do
|
113
|
+
allow(subject).to receive(:raw_info) {
|
114
|
+
{
|
115
|
+
"birthdate" => "",
|
116
|
+
"date_joined" => "2010-01-01"
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
120
|
+
it 'returns nil' do
|
121
|
+
expect(subject.info[:birthdate]).to be_nil
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
require 'omniauth-oauth2'
|
8
|
+
require 'omniauth-underarmour'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include WebMock::API
|
12
|
+
config.include Rack::Test::Methods
|
13
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-underarmour
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Baev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-09 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.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: multi_xml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: OmniAuth OAuth2 strategy for UnderArmour
|
42
|
+
email:
|
43
|
+
- tinbka@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.md
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- example/Gemfile
|
54
|
+
- example/example.rb
|
55
|
+
- lib/omniauth-underarmour.rb
|
56
|
+
- lib/omniauth-underarmour/version.rb
|
57
|
+
- lib/omniauth/strategies/underarmour.rb
|
58
|
+
- omniauth-underarmour.gemspec
|
59
|
+
- spec/omniauth/strategies/underarmour_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
homepage: https://github.com/tinbka/omniauth-underarmour
|
62
|
+
licenses: []
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.8
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: OmniAuth OAuth2 strategy for UnderArmour
|
84
|
+
test_files:
|
85
|
+
- spec/omniauth/strategies/underarmour_spec.rb
|
86
|
+
- spec/spec_helper.rb
|