omniauth-wonde 0.1.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
+ SHA256:
3
+ metadata.gz: 1f4cafe73363a4b663a6353606e0740b5d5a11aec5d594d82a3385dac52f64f5
4
+ data.tar.gz: '0184c9eaafa3fe880391cf4493e1ad90bc5542ca1b2492c25e91cd3a72b85455'
5
+ SHA512:
6
+ metadata.gz: f568386ac13ba3d620bd577318a23f800de8c879604e746b9e6b27f309c47f69e75d2590be0eb0d78c626fc6dd479d71455880d26c8a3c208fbc13a53a5fbf8e
7
+ data.tar.gz: 00b04b4024d16552abec0ac76dd2f30f38ab659fa5af7829a553458c95a78ad1380bc28ec41ea41204a419afae8b77f4519b2537726a9b33e949f80b33d8c428
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /Gemfile.lock
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ inherit_gem:
2
+ relaxed-rubocop: .rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.3
6
+
7
+ Layout/AlignArguments:
8
+ EnforcedStyle: with_fixed_indentation
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - "spec/**/*.rb"
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5.3
9
+ - 2.6
10
+ - ruby-head
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
14
+ fast_finish: true
15
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in omniauth-wonde.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tom Crouch
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.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # OmniAuth::Wonde
2
+
3
+ Strategy to authenticate with Wonde via OAuth2 in OmniAuth.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-wonde'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-wonde
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tcrouch/omniauth-wonde.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "omniauth/wonde"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,43 @@
1
+ {
2
+ Me {
3
+ id
4
+ Person {
5
+ ... on Student {
6
+ id
7
+ type
8
+ forename
9
+ middle_names
10
+ surname
11
+ upi
12
+ School {
13
+ id
14
+ name
15
+ }
16
+ }
17
+ ... on Employee {
18
+ id
19
+ type
20
+ forename
21
+ middle_names
22
+ surname
23
+ upi
24
+ School {
25
+ id
26
+ name
27
+ }
28
+ }
29
+ ... on Contact {
30
+ id
31
+ type
32
+ forename
33
+ middle_names
34
+ surname
35
+ upi
36
+ School {
37
+ id
38
+ name
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ # Authentication strategy for Wonde
8
+ #
9
+ # Wonde implements OAuth 2 (three legged)
10
+ class Wonde < OmniAuth::Strategies::OAuth2
11
+ USER_INFO_URL = "https://api.wonde.com/graphql/me"
12
+
13
+ option :name, "wonde"
14
+ option :provider_ignores_state, true
15
+ option :authorize_options, %i[scope redirect_uri]
16
+ option :client_options,
17
+ site: "https://edu.wonde.com",
18
+ authorize_url: "https://edu.wonde.com/oauth/authorize",
19
+ token_url: "https://api.wonde.com/oauth/token"
20
+
21
+ uid { raw_info.dig("Me", "id") }
22
+
23
+ info do
24
+ me = raw_info.dig("Me", "Person") || {}
25
+ prune!(
26
+ first_name: me["forename"],
27
+ last_name: me["surname"],
28
+ middle_names: me["middle_names"],
29
+ person_id: me["id"],
30
+ person_type: me["type"],
31
+ school_id: me.dig("School", "id"),
32
+ school_name: me.dig("School", "name"),
33
+ upi: me["upi"]
34
+ )
35
+ end
36
+
37
+ extra do
38
+ prune!(
39
+ raw_info: raw_info
40
+ )
41
+ end
42
+
43
+ # @return [String] JSON string
44
+ def self.user_query_body
45
+ @user_query_body ||= begin
46
+ gql = File.read(File.expand_path("user_data.graphql", __dir__))
47
+ { query: gql }.to_json
48
+ end
49
+ end
50
+
51
+ # @return [Hash]
52
+ def raw_info
53
+ @raw_info ||= begin
54
+ data = fetch_user_info.parsed || {}
55
+ data["data"] || {}
56
+ end
57
+ end
58
+
59
+ # @return [String]
60
+ def callback_url
61
+ options[:redirect_uri] ||
62
+ (
63
+ full_host +
64
+ script_name +
65
+ callback_path
66
+ )
67
+ # "#{full_host}#{script_name}#{callback_path}"
68
+ end
69
+
70
+ private
71
+
72
+ # Retrieve basic user info
73
+ #
74
+ # POST to Wonde GraphQL API
75
+ def fetch_user_info
76
+ access_token.post(USER_INFO_URL) do |req|
77
+ req.headers['Content-Type'] = "application/json"
78
+ req.body = self.class.user_query_body
79
+ end
80
+ end
81
+
82
+ # Remove empty values from hash
83
+ #
84
+ # @param hash [Hash]
85
+ # @return [Hash]
86
+ def prune!(hash)
87
+ hash.delete_if do |_, v|
88
+ prune!(v) if v.is_a?(Hash)
89
+ v.nil? || (v.respond_to?(:empty?) && v.empty?)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "omniauth/wonde/version"
4
+ require "omniauth/strategies/wonde"
5
+
6
+ module OmniAuth
7
+ module Wonde
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Wonde
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "omniauth/wonde/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "omniauth-wonde"
9
+ spec.version = OmniAuth::Wonde::VERSION
10
+ spec.authors = ["Tom Crouch"]
11
+ spec.email = ["tom.crouch@gmail.com"]
12
+
13
+ spec.summary = "OmniAuth strategy for Wonde"
14
+ spec.homepage = "https://github.com/tcrouch/omniauth-wonde"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+ spec.required_ruby_version = ">= 2.3.0"
26
+
27
+ spec.add_runtime_dependency "omniauth-oauth2"
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "relaxed-rubocop", "~> 2.4"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "rubocop", "~> 0.74"
34
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-wonde
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom Crouch
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-12 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: relaxed-rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.4'
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
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.74'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.74'
97
+ description:
98
+ email:
99
+ - tom.crouch@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/omniauth/strategies/user_data.graphql
115
+ - lib/omniauth/strategies/wonde.rb
116
+ - lib/omniauth/wonde.rb
117
+ - lib/omniauth/wonde/version.rb
118
+ - omniauth-wonde.gemspec
119
+ homepage: https://github.com/tcrouch/omniauth-wonde
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.3.0
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.6
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: OmniAuth strategy for Wonde
143
+ test_files: []