omniauth-nokia 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23a908ba4c27cf05f57a38f19c0362205d530fb2d36e1c8b500b74bde635c598
4
+ data.tar.gz: 2222f833b7f1827523eddefdca5e0a05c4d00dfe87a43396ae2257acedabbca3
5
+ SHA512:
6
+ metadata.gz: e5b3154134899106dbafe23412e0f44c6d6b5fe04e63da7308cf8dc01574d3dc08afffc093d689648ab5c01f0e8236b63811ffe562d9e45b0ff052d6c8027de0
7
+ data.tar.gz: 8b552394e5b134183d38f975f1a59223e0a095b56818db7205e09b6c7bb6b9cb3d5ca3b2149ed198596f7b4912268d3da548b398c9bacf3632998590fa276360
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.4
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in omniauth-nokia.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Daniel Nelson
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,126 @@
1
+ # OmniAuth Nokia Strategy
2
+
3
+ This is an OmniAuth OAuth 1.0 strategy for authenticating with the [Nokia OAuth 1.0 api](see https://developer.health.nokia.com/api).
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'omniauth-nokia'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install omniauth-nokia
22
+
23
+
24
+ ## Get your Nokia credentials
25
+
26
+ To register your application with Nokia and obtain a consumer key and secret, go to the [Nokia application registration](https://developer.health.nokia.com/partner/add).
27
+
28
+ ## Running the example
29
+
30
+ $ cd example
31
+ $ bundle
32
+ $ NOKIA_API_KEY=<your_nokia_api_key> NOKIA_API_SECRET=<your_nokia_api_secret> bundle exec ruby example.rb
33
+ Visit http://localhost:4567/ in a browser
34
+
35
+ ## Usage
36
+
37
+ Add the strategy to your `Gemfile`:
38
+
39
+ ```ruby
40
+ gem 'omniauth-nokia'
41
+ ```
42
+
43
+ Then integrate the strategy into your middleware:
44
+
45
+ ```ruby
46
+ use OmniAuth::Builder do
47
+ provider :nokia,
48
+ ENV['NOKIA_API_KEY'],
49
+ ENV['NOKIA_API_SECRET']
50
+ end
51
+ ```
52
+
53
+ In Rails, create a new file under config/initializers called omniauth.rb to plug the strategy into your middleware stack.
54
+
55
+ ```ruby
56
+ Rails.application.config.middleware.use OmniAuth::Builder do
57
+ provider :nokia,
58
+ ENV['NOKIA_API_KEY'],
59
+ ENV['NOKIA_API_SECRET']
60
+ end
61
+ ```
62
+
63
+ In your controller action (responding to /auth/nokia/callback), get nokia_user_id, nokia_user_access_token, nokia_user_access_token_secret from the omniauth.auth params and store them for later interaction with the API:
64
+
65
+ ```ruby
66
+ nokia_params = request.env['omniauth.auth']
67
+ nokia_user_id = nokia_params['uid']
68
+ nokia_user_access_token = nokia_params['extra']['access_token'].token
69
+ nokia_user_access_token_secret = nokia_params['extra']['access_token'].secret
70
+ ```
71
+
72
+ To interact with the Nokia API (e.g. retrieve weight measurements recorded by a Nokia scale):
73
+
74
+ ```ruby
75
+ oauth_consumer = OAuth::Consumer.new(
76
+ ENV['NOKIA_API_KEY'],
77
+ ENV['NOKIA_API_SECRET'],
78
+ OmniAuth::Strategies::Nokia.consumer_options,
79
+ )
80
+
81
+ api_access_token = OAuth::AccessToken.from_hash(oauth_consumer, {
82
+ oauth_token: nokia_user_access_token,
83
+ oauth_token_secret: nokia_user_access_token_secret,
84
+ })
85
+
86
+ # Change the uri to access other Nokia API endpoints
87
+ uri = "https://api.health.nokia.com/measure?action=getmeas&userid=#{nokia_user_id}"
88
+
89
+ request = api_access_token.get(uri)
90
+ JSON.parse(request.body)
91
+ ```
92
+
93
+ ## About OmniAuth
94
+
95
+ For additional information about OmniAuth, visit [OmniAuth wiki](https://github.com/intridea/omniauth/wiki).
96
+
97
+ 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/).
98
+
99
+ (The above adapted from [omniauth-fitbit](https://github.com/tkgospodinov/omniauth-fitbit))
100
+
101
+ ## Contributing
102
+
103
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/omniauth-nokia.
104
+
105
+ ## Original License
106
+
107
+ Copyright (c) 2016 TK Gospodinov. See [LICENSE](https://github.com/tkgospodinov/omniauth-fitbit/blob/master/LICENSE.md) for details.
108
+
109
+ Permission is hereby granted, free of charge, to any person obtaining
110
+ a copy of this software and associated documentation files (the
111
+ "Software"), to deal in the Software without restriction, including
112
+ without limitation the rights to use, copy, modify, merge, publish,
113
+ distribute, sublicense, and/or sell copies of the Software, and to
114
+ permit persons to whom the Software is furnished to do so, subject to
115
+ the following conditions:
116
+
117
+ The above copyright notice and this permission notice shall be
118
+ included in all copies or substantial portions of the Software.
119
+
120
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
121
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
122
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
123
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
124
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
125
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
126
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/nokia"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'omniauth-nokia', path: '../'
4
+ gem 'oauth', path: '/Users/danielnelson/work/reference/oauth-ruby/'
5
+ gem 'pry'
6
+ gem 'pry-stack_explorer'
7
+ gem 'sinatra'
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ omniauth-nokia (0.0.1)
5
+ oauth (~> 0.5)
6
+ omniauth-oauth (~> 1.1)
7
+
8
+ PATH
9
+ remote: /Users/danielnelson/work/reference/oauth-ruby
10
+ specs:
11
+ oauth (0.5.4)
12
+
13
+ GEM
14
+ remote: http://rubygems.org/
15
+ specs:
16
+ binding_of_caller (0.8.0)
17
+ debug_inspector (>= 0.0.1)
18
+ coderay (1.1.1)
19
+ debug_inspector (0.0.3)
20
+ hashie (3.5.7)
21
+ method_source (0.8.2)
22
+ mustermann (1.0.2)
23
+ omniauth (1.8.1)
24
+ hashie (>= 3.4.6, < 3.6.0)
25
+ rack (>= 1.6.2, < 3)
26
+ omniauth-oauth (1.1.0)
27
+ oauth
28
+ omniauth (~> 1.0)
29
+ pry (0.10.4)
30
+ coderay (~> 1.1.0)
31
+ method_source (~> 0.8.1)
32
+ slop (~> 3.4)
33
+ pry-stack_explorer (0.4.9.2)
34
+ binding_of_caller (>= 0.7)
35
+ pry (>= 0.9.11)
36
+ rack (2.0.4)
37
+ rack-protection (2.0.1)
38
+ rack
39
+ sinatra (2.0.1)
40
+ mustermann (~> 1.0)
41
+ rack (~> 2.0)
42
+ rack-protection (= 2.0.1)
43
+ tilt (~> 2.0)
44
+ slop (3.6.0)
45
+ tilt (2.0.8)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ oauth!
52
+ omniauth-nokia!
53
+ pry
54
+ pry-stack_explorer
55
+ sinatra
56
+
57
+ BUNDLED WITH
58
+ 1.16.1
@@ -0,0 +1,52 @@
1
+ require 'sinatra'
2
+ require 'omniauth-nokia'
3
+ require 'pry'
4
+
5
+ use Rack::Session::Cookie
6
+ use OmniAuth::Builder do
7
+ provider :nokia,
8
+ ENV['NOKIA_API_KEY'],
9
+ ENV['NOKIA_API_SECRET']
10
+ end
11
+
12
+ get '/' do
13
+ <<-HTML
14
+ <a href='/auth/nokia'>Sign in with Nokia</a>
15
+ HTML
16
+ end
17
+
18
+ get '/auth/nokia/callback' do
19
+ nokia_params = request.env['omniauth.auth']
20
+
21
+ ##################################
22
+ ### Store these for future use ###
23
+ nokia_user_id = nokia_params['uid']
24
+ nokia_user_access_token = nokia_params['extra']['access_token'].token
25
+ nokia_user_access_token_secret = nokia_params['extra']['access_token'].secret
26
+ ### Store these for future use ###
27
+ ##################################
28
+
29
+ ###################################
30
+ ### Interact with the Nokia API ###
31
+ oauth_consumer = OAuth::Consumer.new(
32
+ ENV['NOKIA_API_KEY'],
33
+ ENV['NOKIA_API_SECRET'],
34
+ OmniAuth::Strategies::Nokia.consumer_options,
35
+ )
36
+
37
+ api_access_token = OAuth::AccessToken.from_hash(oauth_consumer, {
38
+ oauth_token: nokia_user_access_token,
39
+ oauth_token_secret: nokia_user_access_token_secret,
40
+ })
41
+
42
+ # Change the uri to access other Nokia API endpoints
43
+ uri = "https://api.health.nokia.com/measure?action=getmeas&userid=#{nokia_user_id}"
44
+
45
+ request = api_access_token.get(uri)
46
+ # MultiJson.load(request.body)
47
+
48
+ ### Interact with the Nokia API ###
49
+ ###################################
50
+
51
+ request.body
52
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth-nokia/version'
2
+ require 'omniauth/strategies/nokia'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Nokia
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ require 'omniauth-oauth'
2
+ module OmniAuth
3
+ module Strategies
4
+ class Nokia < OmniAuth::Strategies::OAuth
5
+
6
+ def self.consumer_options
7
+ {
8
+ site: 'https://developer.health.nokia.com',
9
+ signature_method: 'HMAC-SHA1',
10
+ request_token_path: '/account/request_token',
11
+ authorize_path: '/account/authorize',
12
+ access_token_path: '/account/access_token',
13
+ scheme: 'query_string',
14
+ http_method: 'get',
15
+ debug_output: true,
16
+ }
17
+ end
18
+
19
+ # Give your strategy a name.
20
+ option :name, 'nokia'
21
+
22
+ # This is where you pass the options you would pass when
23
+ # initializing your consumer from the OAuth gem.
24
+ option :client_options, OmniAuth::Strategies::Nokia.consumer_options
25
+
26
+ # These are called after authentication has succeeded. If
27
+ # possible, you should try to set the UID without making
28
+ # additional calls (if the user id is returned with the token
29
+ # or as a URI parameter). This may not be possible with all
30
+ # providers.
31
+ uid { request.params['userid'] }
32
+
33
+ credentials do
34
+ {
35
+ token: request.params['oauth_token'],
36
+ secret: request.params['oauth_verifier'],
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,39 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "omniauth-nokia/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-nokia"
8
+ spec.version = OmniAuth::Nokia::VERSION
9
+ spec.authors = ["Daniel Nelson"]
10
+ spec.email = ["daniel@platejoy.com"]
11
+
12
+ spec.summary = %q{OmniAuth OAuth1 strategy for Nokia}
13
+ spec.description = %q{OmniAuth OAuth1 strategy for Nokia}
14
+ spec.homepage = "http://github.com/platejoy/omniauth-nokia"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_runtime_dependency 'oauth', '~> 0.5'
34
+ spec.add_runtime_dependency 'omniauth-oauth', '~> 1.1'
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-nokia
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Nelson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: OmniAuth OAuth1 strategy for Nokia
84
+ email:
85
+ - daniel@platejoy.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - example/Gemfile
100
+ - example/Gemfile.lock
101
+ - example/example.rb
102
+ - lib/omniauth-nokia.rb
103
+ - lib/omniauth-nokia/version.rb
104
+ - lib/omniauth/strategies/nokia.rb
105
+ - omniauth-nokia.gemspec
106
+ homepage: http://github.com/platejoy/omniauth-nokia
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ allowed_push_host: https://rubygems.org
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.7.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: OmniAuth OAuth1 strategy for Nokia
131
+ test_files: []