omniauth-memair 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d421628dde318deeed66c7cd016a6c3e6c3f6e4e
4
+ data.tar.gz: '092e3bcef21e804de88fdf976a1ecf87b886231d'
5
+ SHA512:
6
+ metadata.gz: f1e583e58d77bbf8dc9e1eba894f8eef23daac50d5b80de1e75a2a4b35b6e8ec342aabe667886fae6c786d81fb88e8f15ce96785fd4741bcb0ef92c3b72eecc3
7
+ data.tar.gz: 9e15ea4737ad7c4564ece265c767fda6ff0eafcbc519a337a1cace759efa65b1e0c0972420d8351976b65b47c162fc4950a35c96ab014997b42bd934cc3bf22f
data/.gitignore ADDED
@@ -0,0 +1,51 @@
1
+ *.rbc
2
+ capybara-*.html
3
+ .rspec
4
+ /log
5
+ /tmp
6
+ /db/*.sqlite3
7
+ /db/*.sqlite3-journal
8
+ /public/system
9
+ /coverage/
10
+ /spec/tmp
11
+ *.orig
12
+ rerun.txt
13
+ pickle-email-*.html
14
+
15
+ # TODO Comment out this rule if you are OK with secrets being uploaded to the repo
16
+ config/initializers/secret_token.rb
17
+ config/master.key
18
+
19
+ # Only include if you have production secrets in this file, which is no longer a Rails default
20
+ # config/secrets.yml
21
+
22
+ # dotenv
23
+ # TODO Comment out this rule if environment variables can be committed
24
+ .env
25
+
26
+ ## Environment normalization:
27
+ /.bundle
28
+ /vendor/bundle
29
+
30
+ # these should all be checked in to normalize the environment:
31
+ # Gemfile.lock, .ruby-version, .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+
36
+ # if using bower-rails ignore default bower_components path bower.json files
37
+ /vendor/assets/bower_components
38
+ *.bowerrc
39
+ bower.json
40
+
41
+ # Ignore pow environment settings
42
+ .powenv
43
+
44
+ # Ignore Byebug command history file.
45
+ .byebug_history
46
+
47
+ # Ignore node_modules
48
+ node_modules/
49
+
50
+ # Scracth
51
+ scratch.*
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-memair.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ gem 'rake'
13
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Memair
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ [![Gem](https://img.shields.io/gem/v/gstatsat.svg?style=flat)](http://rubygems.org/gems/omniauth-memair)
2
+ [![License](http://img.shields.io/badge/license-MIT-yellow.svg?style=flat)](https://github.com/memair/omniauth-memair/blob/master/LICENSE)
3
+ [![Gregology](https://img.shields.io/badge/contact-Gregology-blue.svg?style=flat)](http://gregology.net/contact/)
4
+ [![Downloads](https://img.shields.io/gem/dt/gstatsat.svg?style=flat)](http://rubygems.org/gems/omniauth-memair)
5
+
6
+ # Omniauth-memair
7
+
8
+ Memair OAuth2 Strategy for OmniAuth.
9
+
10
+ Read the Memair API documentation for more details: https://docs.memair.com/#authenticationcreate_an_app
11
+
12
+ ## Installing
13
+
14
+ Add to your `Gemfile`:
15
+
16
+ ```ruby
17
+ gem 'omniauth-memair'
18
+ ```
19
+
20
+ Then `bundle install`.
21
+
22
+ ## Usage
23
+
24
+ `OmniAuth::Strategies::Memair` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.
25
+
26
+ Ensure your Memair app has the `user_details` scope. Then add the middleware to a Rails app in `config/initializers/omniauth.rb`:
27
+
28
+ ```ruby
29
+ Rails.application.config.middleware.use OmniAuth::Builder do
30
+ provider :memair, ENV['MEMAIR_CLIENT_ID'], ENV['MEMAIR_CLIENT_SECRET']
31
+ end
32
+ ```
33
+
34
+ You can pass multiple scopes. For example to read and write a user's biometric data set the scope to `biometric_read biometric_write`
35
+
36
+ ```ruby
37
+ Rails.application.config.middleware.use OmniAuth::Builder do
38
+ provider :memair, ENV['MEMAIR_CLIENT_ID'], ENV['MEMAIR_CLIENT_SECRET'], scope: 'biometric_read biometric_write'
39
+ end
40
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-memair/version"
2
+ require 'omniauth/strategies/memair'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Memair
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'omniauth-oauth2'
2
+ require 'httparty'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Memair < OmniAuth::Strategies::OAuth2
7
+ DEFAULT_SCOPE = 'user_details'
8
+
9
+ option :client_options, {
10
+ :site => 'https://memair.com',
11
+ :authorize_url => 'https://memair.com/oauth/authorize',
12
+ :token_url => 'https://memair.com/oauth/token'
13
+ }
14
+
15
+ option :authorize_options, [:scope, :permissions]
16
+
17
+ uid { raw_info['data']['UserDetails']['id'].to_s }
18
+
19
+ info do
20
+ {
21
+ 'id' => raw_info['data']['UserDetails']['id'],
22
+ 'email' => raw_info['data']['UserDetails']['email'],
23
+ 'timezone' => raw_info['data']['UserDetails']['timezone'],
24
+ }
25
+ end
26
+
27
+ def request_phase
28
+ super
29
+ end
30
+
31
+ def authorize_params
32
+ super.tap do |params|
33
+ options[:authorize_options].each do |option|
34
+ params[option] = request.params[option.to_s] if request.params[option.to_s]
35
+ end
36
+
37
+ params[:redirect_uri] = options[:redirect_uri] unless options[:redirect_uri].nil?
38
+
39
+ params[:scope] = params[:scope]&.include?(DEFAULT_SCOPE) ? params[:scope] : (DEFAULT_SCOPE + ' ' + params[:scope].to_s).strip
40
+ end
41
+ end
42
+
43
+ def raw_info
44
+ @raw_info ||= HTTParty.post("https://memair.com/graphql", body: { access_token: access_token.token, query: 'query get_user_details{UserDetails{id email timezone}}' }, timeout: 180)
45
+ rescue ::Errno::ETIMEDOUT
46
+ raise ::Timeout::Error
47
+ rescue ::OAuth::Error => e
48
+ raise e.response.inspect
49
+ end
50
+
51
+ def callback_url
52
+ full_host + script_name + callback_path
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ OmniAuth.config.add_camelization 'memair', 'Memair'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-memair/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Greg Clarke"]
6
+ gem.email = ["greg@gho.st"]
7
+ gem.description = %q{Official OmniAuth strategy for Memair.}
8
+ gem.summary = %q{Official OmniAuth strategy for Memair.}
9
+ gem.homepage = "https://github.com/memair/omniauth-memair"
10
+ gem.license = "MIT"
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.name = "omniauth-memair"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::Memair::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.5'
19
+ gem.add_dependency 'omniauth-oauth2', '>= 1.4.0', '< 2.0'
20
+ gem.add_dependency 'httparty', '~> 0.16'
21
+ gem.add_development_dependency 'rspec', '~> 3.5'
22
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-memair
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Greg Clarke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.4.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: httparty
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.16'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.16'
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.5'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.5'
75
+ description: Official OmniAuth strategy for Memair.
76
+ email:
77
+ - greg@gho.st
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - Gemfile
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - lib/omniauth-memair.rb
88
+ - lib/omniauth-memair/version.rb
89
+ - lib/omniauth/strategies/memair.rb
90
+ - omniauth-memair.gemspec
91
+ homepage: https://github.com/memair/omniauth-memair
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.5.2.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Official OmniAuth strategy for Memair.
115
+ test_files: []