omniauth-withings2 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -16
- data/example/example.rb +1 -1
- data/lib/omniauth-withings2/version.rb +2 -2
- data/lib/omniauth/strategies/withings2.rb +10 -4
- data/spec/omniauth/strategies/withings2_spec.rb +2 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08624a2d79a50e39c8de66098b50c57a46776bf15babd0b8d818108dace9aa0f'
|
4
|
+
data.tar.gz: ee9a8079a1118bd64ae9636f964b1c482b37cc857398fdadb248a03ff9c163bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d455e437271b254c9172c10acfc75e3849cf4b96a57c65dfaa9b057f0e91877d80daff6bc84a05fe262df91b32a58a90d7a6158ec09976b6b8102fff77adc231
|
7
|
+
data.tar.gz: 5b786596798d54b04c72d80dcac81f694192736a5c7c7b0ae54764f15c8d0688f4cdda99e2f8d239b177313ffbdeb0f36761c0030c296ce40d7a33d6cb121fe9
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# OmniAuth Withings2 Strategy
|
2
2
|
|
3
|
-
This is an OmniAuth OAuth 2.0 strategy for authenticating with the [Nokia OAuth 2.0
|
3
|
+
This is an OmniAuth OAuth 2.0 strategy for authenticating with the [Withings (formerly Nokia Health) OAuth 2.0 API](see http://developer.withings.com/oauth2/#tag/OAuth-2.0).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -21,13 +21,13 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Get your Oauth credentials
|
23
23
|
|
24
|
-
To register your application with
|
24
|
+
To register your application with Withings and obtain a client id and consumer secret, go to the [Withings developer application registration](https://account.withings.com/partner/account_login?b=add_oauth2).
|
25
25
|
|
26
26
|
## Running the example
|
27
27
|
|
28
28
|
$ cd example
|
29
29
|
$ bundle
|
30
|
-
$
|
30
|
+
$ WITHINGS_CLIENT_ID=<your_withings_client_id> WITHINGS_CLIENT_SECRET=<your_withings_client_secret> bundle exec ruby example.rb
|
31
31
|
Visit http://localhost:4567/ in a browser
|
32
32
|
|
33
33
|
## Usage
|
@@ -44,7 +44,7 @@ Then integrate the strategy into your middleware:
|
|
44
44
|
use OmniAuth::Builder do
|
45
45
|
provider :withings2,
|
46
46
|
ENV['WITHINGS_CLIENT_ID'],
|
47
|
-
ENV['
|
47
|
+
ENV['WITHINGS_CLIENT_SECRET'],
|
48
48
|
scope: 'user.metrics'
|
49
49
|
end
|
50
50
|
```
|
@@ -55,34 +55,34 @@ In Rails, create a new file under config/initializers called omniauth.rb to plug
|
|
55
55
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
56
56
|
provider :withings2,
|
57
57
|
ENV['WITHINGS_CLIENT_ID'],
|
58
|
-
ENV['
|
58
|
+
ENV['WITHINGS_CLIENT_SECRET'],
|
59
59
|
scope: 'user.metrics'
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
63
|
-
In your controller action (responding to /auth/
|
63
|
+
In your controller action (responding to /auth/withings2/callback), get the credentials and store them for later interaction with the API:
|
64
64
|
|
65
65
|
```ruby
|
66
66
|
request.env['omniauth.auth']['credentials']
|
67
67
|
```
|
68
68
|
|
69
69
|
### TODO: update
|
70
|
-
To interact with the
|
70
|
+
To interact with the Withings API (e.g. retrieve weight measurements recorded by a Nokia/Withings scale):
|
71
71
|
|
72
72
|
```ruby
|
73
73
|
oauth_consumer = OAuth::Consumer.new(
|
74
|
-
ENV['
|
75
|
-
ENV['
|
76
|
-
OmniAuth::Strategies::
|
74
|
+
ENV['WITHINGS_CLIENT_ID'],
|
75
|
+
ENV['WITHINGS_CLIENT_SECRET'],
|
76
|
+
OmniAuth::Strategies::Withings.consumer_options,
|
77
77
|
)
|
78
78
|
|
79
79
|
api_access_token = OAuth::AccessToken.from_hash(oauth_consumer, {
|
80
|
-
oauth_token:
|
81
|
-
oauth_token_secret:
|
80
|
+
oauth_token: withings_user_access_token,
|
81
|
+
oauth_token_secret: withings_user_access_token_secret,
|
82
82
|
})
|
83
83
|
|
84
|
-
# Change the uri to access other
|
85
|
-
uri = "https://wbsapi.withings.net/measure?action=getmeas&userid=#{
|
84
|
+
# Change the uri to access other Withings API endpoints
|
85
|
+
uri = "https://wbsapi.withings.net/measure?action=getmeas&userid=#{withings_user_id}"
|
86
86
|
|
87
87
|
request = api_access_token.get(uri)
|
88
88
|
JSON.parse(request.body)
|
@@ -99,11 +99,11 @@ For a short tutorial on how to use OmniAuth in your Rails application, visit [th
|
|
99
99
|
|
100
100
|
## Contributing
|
101
101
|
|
102
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
102
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/platejoy/omniauth-withings2.
|
103
103
|
|
104
104
|
## Original License
|
105
105
|
|
106
|
-
Copyright (c) 2016 TK Gospodinov. See [LICENSE](https://github.com/
|
106
|
+
Copyright (c) 2016 TK Gospodinov. See [LICENSE](https://github.com/platejoy/omniauth-withings2/blob/master/LICENSE.md) for details.
|
107
107
|
|
108
108
|
Permission is hereby granted, free of charge, to any person obtaining
|
109
109
|
a copy of this software and associated documentation files (the
|
data/example/example.rb
CHANGED
@@ -4,7 +4,7 @@ require 'pry'
|
|
4
4
|
|
5
5
|
use Rack::Session::Cookie
|
6
6
|
use OmniAuth::Builder do
|
7
|
-
provider :withings2, ENV['WITHINGS_CLIENT_ID'], ENV['
|
7
|
+
provider :withings2, ENV['WITHINGS_CLIENT_ID'], ENV['WITHINGS_CLIENT_SECRET'], { :scope => 'user.metrics', :redirect_uri => 'http://localhost:4567/auth/withings2/callback' }
|
8
8
|
end
|
9
9
|
|
10
10
|
get '/' do
|
@@ -6,16 +6,22 @@ module OmniAuth
|
|
6
6
|
|
7
7
|
option :name, 'withings2'
|
8
8
|
option :client_options, {
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
:site => 'https://account.withings.com',
|
10
|
+
:authorize_url => 'https://account.withings.com/oauth2_user/authorize2',
|
11
|
+
:token_url => 'https://wbsapi.withings.net/v2/oauth2',
|
12
|
+
extract_access_token: proc { |client, hash|
|
13
|
+
::OAuth2::Client::DEFAULT_EXTRACT_ACCESS_TOKEN.call(client, hash['body'])
|
14
|
+
}
|
12
15
|
}
|
13
16
|
|
14
17
|
option :response_type, 'code'
|
15
18
|
option :authorize_options, %i(scope response_type redirect_uri)
|
16
19
|
|
17
20
|
def build_access_token
|
18
|
-
options.token_params.merge!(
|
21
|
+
options.token_params.merge!(
|
22
|
+
action: 'requesttoken',
|
23
|
+
headers: { 'Authorization' => basic_auth_header }
|
24
|
+
)
|
19
25
|
super
|
20
26
|
end
|
21
27
|
|
@@ -35,7 +35,7 @@ describe "OmniAuth::Strategies::Withings2" do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'has correct token url' do
|
38
|
-
expect(subject.options.client_options.token_url).to eq('https://
|
38
|
+
expect(subject.options.client_options.token_url).to eq('https://wbsapi.withings.net/v2/oauth2')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -53,7 +53,7 @@ describe "OmniAuth::Strategies::Withings2" do
|
|
53
53
|
context 'uid' do
|
54
54
|
before :each do
|
55
55
|
access_token = double('access_token')
|
56
|
-
allow(access_token).to receive('params') { { '
|
56
|
+
allow(access_token).to receive('params') { { 'userid' => '123ABC' } }
|
57
57
|
allow(subject).to receive(:access_token) { access_token }
|
58
58
|
end
|
59
59
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-withings2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth-oauth2
|
@@ -64,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
|
-
|
68
|
-
rubygems_version: 2.7.6
|
67
|
+
rubygems_version: 3.0.3
|
69
68
|
signing_key:
|
70
69
|
specification_version: 4
|
71
70
|
summary: OmniAuth OAuth2 strategy for Withings
|