omniauth-fitbit-oauth2 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +24 -0
- data/exmaple/Gemfile +4 -0
- data/exmaple/config.ru +28 -0
- data/lib/omniauth-fitbit-oauth2.rb +2 -0
- data/lib/omniauth-fitbit-oauth2/version.rb +5 -0
- data/lib/omniauth/strategies/fitbit_oauth2.rb +70 -0
- data/omniauth-fitbit-oauth2.gemspec +22 -0
- data/spec/omniauth/strategies/fitbit_oauth2_spec.rb +24 -0
- data/spec/spec_helper.rb +4 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fdcf3a2f76bad287cc9dbeccef7692c15ab260da
|
4
|
+
data.tar.gz: 83b9db84c215c64882361cecad505a21fdea2ae3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98586420ee60eb52bad0e53f61f5c54db69a54cb5994b0d9dd3d0e6c7b9abfe639fa13c12019ff7edb07a2cc75dbf5afd678ec68dbe91359ecb0b5bf8863c55f
|
7
|
+
data.tar.gz: 5c3447dcbc9067e83be290d1c66e98ad9520dd64a62df63c9895f50d57cee5148f652b45067a600c194a9c97493da123944a1076441405557e6c5e079b1b7a65
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
Gemfile.lock
|
31
|
+
.ruby-version
|
32
|
+
.ruby-gemset
|
33
|
+
.rspec
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Matthew Bender
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# OmniAuth OAuth2 strategy for Fitbit
|
2
|
+
This gem is an OAuth2 OmniAuth Strategy for the [Fitbit API](https://wiki.fitbit.com/display/API/OAuth+2.0).
|
3
|
+
|
4
|
+
## Installing
|
5
|
+
|
6
|
+
Add to your `Gemfile`:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'omniauth-fitbit-oauth2'
|
10
|
+
```
|
11
|
+
|
12
|
+
Then `bundle install`.
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
`OmniAuth::Strategies::FitbitOauth2` is simply a Rack middleware. Read [the OmniAuth 2.0 docs](https://github.com/intridea/omniauth-oauth2) for detailed instructions.
|
17
|
+
|
18
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
22
|
+
provider :fitbit_oauth2, ENV['FITBIT_CLIENT_ID'], ENV['FITBIT_CLIENT_SECRET']
|
23
|
+
end
|
24
|
+
```
|
data/exmaple/Gemfile
ADDED
data/exmaple/config.ru
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'omniauth-fitbit-oauth2'
|
4
|
+
|
5
|
+
class App < Sinatra::Base
|
6
|
+
get '/' do
|
7
|
+
redirect '/auth/fitbit_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 :fitbit_oauth2, ENV['FITBIT_CLIENT_ID'], ENV['FITBIT_CLIENT_SECRET'],
|
25
|
+
:scope => 'activity sleep'
|
26
|
+
end
|
27
|
+
|
28
|
+
run App.new
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class FitbitOauth2 < OmniAuth::Strategies::OAuth2
|
7
|
+
option :name, 'fitbit_oauth2'
|
8
|
+
|
9
|
+
option :client_options,
|
10
|
+
{
|
11
|
+
:site => 'https://api.fitbit.com',
|
12
|
+
:authorize_url => 'https://www.fitbit.com/oauth2/authorize',
|
13
|
+
:token_url => 'https://api.fitbit.com/oauth2/token'
|
14
|
+
}
|
15
|
+
|
16
|
+
option :authorize_options, [:scope, :response_type]
|
17
|
+
option :response_type, 'code'
|
18
|
+
|
19
|
+
def build_access_token
|
20
|
+
options.token_params.merge!(:headers =>
|
21
|
+
{'Authorization' => basic_auth_header})
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def basic_auth_header
|
26
|
+
'Basic ' + Base64.encode64(options[:client_id] + ':' +
|
27
|
+
options[:client_secret]).gsub("\n", '')
|
28
|
+
end
|
29
|
+
|
30
|
+
uid do
|
31
|
+
raw_info['user']['encodedId']
|
32
|
+
end
|
33
|
+
|
34
|
+
info do
|
35
|
+
{
|
36
|
+
:name => raw_info['user']['displayName'],
|
37
|
+
:full_name => raw_info['user']['fullName'],
|
38
|
+
:display_name => raw_info['user']['displayName'],
|
39
|
+
:nickname => raw_info['user']['nickname'],
|
40
|
+
:gender => raw_info['user']['gender'],
|
41
|
+
:about_me => raw_info['user']['aboutMe'],
|
42
|
+
:city => raw_info['user']['city'],
|
43
|
+
:state => raw_info['user']['state'],
|
44
|
+
:country => raw_info['user']['country'],
|
45
|
+
:dob => !raw_info['user']['dateOfBirth'].empty? ? Date.strptime(raw_info['user']['dateOfBirth'], '%Y-%m-%d'):nil,
|
46
|
+
:member_since => Date.strptime(raw_info['user']['memberSince'], '%Y-%m-%d'),
|
47
|
+
:locale => raw_info['user']['locale'],
|
48
|
+
:timezone => raw_info['user']['timezone']
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
extra do
|
53
|
+
{
|
54
|
+
:raw_info => raw_info
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def raw_info
|
59
|
+
if options[:use_english_measure] == 'true'
|
60
|
+
@raw_info ||= MultiJson.load(access_token.
|
61
|
+
request('get', 'https://api.fitbit.com/1/user/-/profile.json',
|
62
|
+
{ 'Accept-Language' => 'en_US' }).body)
|
63
|
+
else
|
64
|
+
@raw_info ||= MultiJson.load(access_token.
|
65
|
+
get('https://api.fitbit.com/1/user/-/profile.json').body)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth-fitbit-oauth2/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'omniauth-fitbit-oauth2'
|
6
|
+
gem.version = OmniAuth::FitbitOauth2::VERSION
|
7
|
+
gem.license = 'MIT'
|
8
|
+
gem.summary = %q{OmniAuth Oauth2 strategy for fitbit.com.}
|
9
|
+
gem.description = %q{OmniAuth Oauth2 strategy for fitbit.com - https://wiki.fitbit.com/display/API/OAuth+2.0}
|
10
|
+
gem.author = 'Matthew Bender'
|
11
|
+
gem.email = 'benderm@gmail.com'
|
12
|
+
gem.homepage = 'https://github.com/codebender/omniauth-fitbit-oauth2'
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.3'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3.2'
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "OmniAuth::Strategies::FitbitOauth2" do
|
4
|
+
subject do
|
5
|
+
OmniAuth::Strategies::FitbitOauth2.new(nil, @options || {})
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'client options' do
|
9
|
+
it 'has correct API site' do
|
10
|
+
expect(subject.options.client_options.site).
|
11
|
+
to eq('https://api.fitbit.com')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has correct token url' do
|
15
|
+
expect(subject.options.client_options.token_url).
|
16
|
+
to eq('https://api.fitbit.com/oauth2/token')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has correct authorize url' do
|
20
|
+
expect(subject.options.client_options.authorize_url).
|
21
|
+
to eq('https://www.fitbit.com/oauth2/authorize')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-fitbit-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Bender
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-15 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'
|
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'
|
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.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
description: OmniAuth Oauth2 strategy for fitbit.com - https://wiki.fitbit.com/display/API/OAuth+2.0
|
42
|
+
email: benderm@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- Gemfile
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- exmaple/Gemfile
|
52
|
+
- exmaple/config.ru
|
53
|
+
- lib/omniauth-fitbit-oauth2.rb
|
54
|
+
- lib/omniauth-fitbit-oauth2/version.rb
|
55
|
+
- lib/omniauth/strategies/fitbit_oauth2.rb
|
56
|
+
- omniauth-fitbit-oauth2.gemspec
|
57
|
+
- spec/omniauth/strategies/fitbit_oauth2_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
homepage: https://github.com/codebender/omniauth-fitbit-oauth2
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: OmniAuth Oauth2 strategy for fitbit.com.
|
83
|
+
test_files:
|
84
|
+
- spec/omniauth/strategies/fitbit_oauth2_spec.rb
|
85
|
+
- spec/spec_helper.rb
|