omniauth-withings-oauth2 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 790581559a7f50a1b2df09ef40cb2d057ce2d08b
4
+ data.tar.gz: d1d7214e92ab218e1cd8b658dd28538d0bcd972e
5
+ SHA512:
6
+ metadata.gz: ab1226627ec664f3b0dace6d7f383b44d58f041788ca96ff7179e8906b0cdd93b23ab5ac05e0f02cab13c8dd433667e6828554b73d5f5177a389caeaad801b5b
7
+ data.tar.gz: f62bd79b20e383e2114acdb95aeb7f575e2b1027acf821250996c7ee365cf6f467b52b33910a845a047ca95636dc1a05ec7ccd651238980ac49250d03ceddb8b
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
+ .ruby-gemset
19
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-withings-oauth2.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2019 Eric Shelley
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,54 @@
1
+ # OmniAuth Withings OAuth2 Strategy
2
+
3
+ [![Build Status](https://travis-ci.org/bartimaeus/omniauth-withings-oauth2.svg?branch=master)](https://travis-ci.org/bartimaeus/omniauth-withings-oauth2)
4
+
5
+ A Withings OAuth2 strategy for OmniAuth.
6
+
7
+ For more details, read the Withings documentation: https://developer.withings.com/oauth2
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'omniauth-withings-oauth2'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install omniauth-withings-oauth2
22
+
23
+ ## Usage
24
+
25
+ Register your application with withings to receive an API credentials: https://account.withings.com/partner/add_oauth2
26
+
27
+ This is an example that you might put into a Rails initializer at `config/initializers/omniauth.rb`:
28
+
29
+ ```ruby
30
+ Rails.application.config.middleware.use OmniAuth::Builder do
31
+ provider :withings, ENV['WITHINGS_CLIENT_ID'], ENV['WITHINGS_CLIENT_SECRET'], :scope => 'user.info user.metrics'
32
+ end
33
+ ```
34
+
35
+ You can now access the OmniAuth withings OAuth2 URL: `/auth/withings`.
36
+
37
+ ## Granting Member Permissions to Your Application
38
+
39
+ With the withings API, you have the ability to specify which permissions you want users to grant your application.
40
+ For more details, read the withings documentation: http://developer.withings.com/oauth2/#tag/scopes
41
+
42
+ You can configure the scope option:
43
+
44
+ ```ruby
45
+ provider :withings, ENV['WITHINGS_CLIENT_ID'], ENV['WITHINGS_CLIENT_SECRET'], :scope => 'user.info user.metrics'
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b features/my-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin features/my-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/example/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'omniauth-withings-oauth2'
data/example/config.ru ADDED
@@ -0,0 +1,31 @@
1
+ # Sample app for Withings OAuth2 Strategy
2
+ # Make sure to setup the ENV variables WITHINGS_CLIENT_ID and WITHINGS_CLIENT_SECRET
3
+ # Run with "bundle exec rackup"
4
+
5
+ require 'bundler/setup'
6
+ require 'sinatra/base'
7
+ require 'omniauth-withings'
8
+
9
+ class App < Sinatra::Base
10
+ get '/' do
11
+ redirect '/auth/withings'
12
+ end
13
+
14
+ get '/auth/:provider/callback' do
15
+ content_type 'application/json'
16
+ MultiJson.encode(request.env['omniauth.auth'])
17
+ end
18
+
19
+ get '/auth/failure' do
20
+ content_type 'application/json'
21
+ MultiJson.encode(request.env)
22
+ end
23
+ end
24
+
25
+ use Rack::Session::Cookie, :secret => 'change_me'
26
+
27
+ use OmniAuth::Builder do
28
+ provider :withings, ENV['WITHINGS_CLIENT_ID'], ENV['WITHINGS_CLIENT_SECRET'], scope: 'user.info user.metrics user.activity'
29
+ end
30
+
31
+ run App.new
@@ -0,0 +1,2 @@
1
+ require "omniauth-withings-oauth2/version"
2
+ require "omniauth/strategies/withings"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module WithingsOauth2
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 Withings < OmniAuth::Strategies::OAuth2
6
+ option :name, 'withings'
7
+
8
+ option :client_options, {
9
+ :site => 'https://account.withings.com',
10
+ :authorize_url => 'https://account.withings.com/oauth2_user/authorize2',
11
+ :token_url => 'https://account.withings.com/oauth2/token'
12
+ }
13
+
14
+ option :scope, 'user.info'
15
+
16
+ uid do
17
+ raw_info['userid']
18
+ end
19
+
20
+ info do
21
+ {
22
+ 'auth' => raw_info
23
+ }
24
+ end
25
+
26
+ def callback_url
27
+ full_host + script_name + callback_path
28
+ end
29
+
30
+ alias :oauth2_access_token :access_token
31
+
32
+ def access_token
33
+ ::OAuth2::AccessToken.new(client, oauth2_access_token.token, {
34
+ :expires_in => oauth2_access_token.expires_in,
35
+ :expires_at => oauth2_access_token.expires_at
36
+ })
37
+ end
38
+
39
+ def raw_info
40
+ oauth2_access_token
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ OmniAuth.config.add_camelization 'withings', 'Withings'
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-withings-oauth2/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omniauth-withings-oauth2"
8
+ gem.version = OmniAuth::WithingsOauth2::VERSION
9
+ gem.authors = ["Eric Shelley"]
10
+ gem.email = ["eric@webdesignbakery.com"]
11
+ gem.description = %q{Withings OAuth2 strategy for OmniAuth.}
12
+ gem.summary = %q{Withings OAuth2 strategy for OmniAuth.}
13
+ gem.homepage = "https://github.com/bartimaeus/omniauth-withings-oauth2"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_runtime_dependency 'omniauth-oauth2', '~> 1.2'
22
+
23
+ gem.add_development_dependency 'bundler', '>= 1.16', '< 3.0'
24
+ gem.add_development_dependency 'rake', '~> 12.3'
25
+
26
+ gem.add_development_dependency 'rspec', '~> 3.6'
27
+ gem.add_development_dependency 'simplecov', '~> 0.16'
28
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-withings-oauth2'
3
+
4
+ describe OmniAuth::Strategies::Withings do
5
+ subject { OmniAuth::Strategies::Withings.new(nil) }
6
+
7
+ it 'adds camelization for itself' do
8
+ expect(OmniAuth::Utils.camelize('withings')).to eq('Withings')
9
+ end
10
+
11
+ describe '#client' do
12
+ it 'has correct Withings site' do
13
+ expect(subject.client.site).to eq('https://account.withings.com')
14
+ end
15
+
16
+ it 'has correct `authorize_url`' do
17
+ expect(subject.client.options[:authorize_url]).to eq('https://account.withings.com/oauth2_user/authorize2')
18
+ end
19
+
20
+ it 'has correct `token_url`' do
21
+ expect(subject.client.options[:token_url]).to eq('https://account.withings.com/oauth2/token')
22
+ end
23
+ end
24
+
25
+ describe '#callback_path' do
26
+ it 'has the correct callback path' do
27
+ expect(subject.callback_path).to eq('/auth/withings/callback')
28
+ end
29
+ end
30
+
31
+ describe '#uid' do
32
+ before :each do
33
+ allow(subject).to receive(:raw_info) { Hash['userid' => 'uid'] }
34
+ end
35
+
36
+ it 'returns the id from raw_info' do
37
+ expect(subject.uid).to eq('uid')
38
+ end
39
+ end
40
+
41
+ describe '#info / #raw_info' do
42
+ let(:access_token) { instance_double OAuth2::AccessToken }
43
+
44
+ before :each do
45
+ allow(subject).to receive(:raw_info) { Hash['something' => 'new'] }
46
+ allow(subject).to receive(:access_token).and_return access_token
47
+ end
48
+
49
+ it 'returns auth key containing raw_info' do
50
+ expect(subject.info).to have_key('auth')
51
+ end
52
+ end
53
+
54
+ describe '#access_token' do
55
+ let(:expires_in) { 3600 }
56
+ let(:expires_at) { 946688400 }
57
+ let(:token) { 'token' }
58
+ let(:access_token) do
59
+ instance_double OAuth2::AccessToken, :expires_in => expires_in,
60
+ :expires_at => expires_at, :token => token
61
+ end
62
+
63
+ before :each do
64
+ # allow(subject).to receive(:raw_info) { Hash['scope' => 'user.info', 'refresh_token' => token, 'access_token' => token, 'expires_at' => expires_at] }
65
+ allow(subject).to receive(:oauth2_access_token).and_return access_token
66
+ end
67
+
68
+ specify { expect(subject.access_token.expires_in).to eq expires_in }
69
+ specify { expect(subject.access_token.expires_at).to eq expires_at }
70
+ end
71
+
72
+ describe '#authorize_params' do
73
+ describe 'scope' do
74
+ before :each do
75
+ allow(subject).to receive(:session).and_return({})
76
+ end
77
+
78
+ it 'sets default scope' do
79
+ expect(subject.authorize_params['scope']).to eq('user.info')
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,19 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # Require this file using `require "spec_helper"` to ensure that it is only
7
+ # loaded once.
8
+ #
9
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
+ RSpec.configure do |config|
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-withings-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Shelley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-04 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.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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3.0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '1.16'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '12.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '12.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.6'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.6'
75
+ - !ruby/object:Gem::Dependency
76
+ name: simplecov
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.16'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.16'
89
+ description: Withings OAuth2 strategy for OmniAuth.
90
+ email:
91
+ - eric@webdesignbakery.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".travis.yml"
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - example/Gemfile
104
+ - example/config.ru
105
+ - lib/omniauth-withings-oauth2.rb
106
+ - lib/omniauth-withings-oauth2/version.rb
107
+ - lib/omniauth/strategies/withings.rb
108
+ - omniauth-withings-oauth2.gemspec
109
+ - spec/omniauth/strategies/withings_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/bartimaeus/omniauth-withings-oauth2
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.5.2.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Withings OAuth2 strategy for OmniAuth.
135
+ test_files:
136
+ - spec/omniauth/strategies/withings_spec.rb
137
+ - spec/spec_helper.rb