omniauth-oauth2-generic 0.2.2

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: c60894fadcf2f9014bc48732350f0294c8743a60
4
+ data.tar.gz: 11bba29d2e3fdea5edeb6eebb2679376dafa5838
5
+ SHA512:
6
+ metadata.gz: cb6e8cee46248d982b1d228e1d0e836b6c52c895b65b7ddb6dd13861150aa63fe20c8c4f8d1c66f2df6eb4704e24300fe9d3b17386d5aabefcc50374b38e5471
7
+ data.tar.gz: c98f7e1af754afb486fc978b37e1f4916afd93a34108bdf9f3df8561ab01f887ee2518a64bfdeda82afc0ff21f93525b26dead3b0684c4193019d57b34cc8821
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --color
3
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-oauth2-generic.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2017 Joe Marty, Jeff Hahn and Internet Exposure.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # omniauth-oauth2-generic
2
+
3
+ By [Internet Exposure](https://www.iexposure.com/)
4
+
5
+ [![build](http://gitlab.iexposure.com/satorix/omniauth-oauth2-generic/badges/master/build.svg)](http://gitlab.iexposure.com/satorix/omniauth-oauth2-generic/pipelines)
6
+ [![coverage](http://gitlab.iexposure.com/satorix/omniauth-oauth2-generic/badges/master/coverage.svg)](http://gitlab.iexposure.com/satorix/omniauth-oauth2-generic/pipelines)
7
+
8
+ This gem provides an OmniAuth strategy for authenticating with an OAuth2 service using the authorization grant flow.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'omniauth-oauth2-generic'
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ Include this gem in your client app [as you would any OmniAuth strategy](https://github.com/omniauth/omniauth#getting-started), by adding it to the middleware stack:
21
+
22
+ **Rails Example: (minimum configuration)**
23
+ ```ruby
24
+ # config/initializers/omniauth.rb
25
+ Rails.application.config.middleware.use OmniAuth::Builder do
26
+ provider :oauth2_generic,
27
+ "Your_OAuth_App_ID", "Your_OAuth_App_Secret",
28
+ client_options: {
29
+ site: 'https://your_oauth_server', # including port if necessary
30
+ user_info_url: '/api/path/to/fetch/current_user/info'
31
+ },
32
+ name: 'Satorix' # optional - alternate name for the strategy (appears in URLs)
33
+ end
34
+ ```
35
+
36
+ **Gitlab Config Example:**
37
+
38
+ ```ruby
39
+ # /etc/gitlab/gitlab.rb
40
+ gitlab_rails['omniauth_enabled'] = true
41
+ gitlab_rails['omniauth_allow_single_sign_on'] = ['oauth2_generic']
42
+ gitlab_rails['omniauth_block_auto_created_users'] = false
43
+ gitlab_rails['omniauth_providers'] = [
44
+ {
45
+ 'name' => 'oauth2_generic',
46
+ 'app_id' => 'oauth_client_app_id',
47
+ 'app_secret' => 'oauth_client_app_secret',
48
+ 'args' => {
49
+ client_options: {
50
+ 'site' => 'https://your_oauth_server', # including port if necessary
51
+ 'user_info_url' => '/api/path/to/fetch/current_user/info'
52
+ },
53
+ # optionally, you can add the following two lines to "white label" the display name
54
+ # of this strategy (appears in urls and Gitlab login buttons)
55
+ # If you do this, you must also replace oauth2_generic, everywhere it appears above, with the new name.
56
+ name: 'Satorix', # display name for this strategy
57
+ strategy_class: "OmniAuth::Strategies::OAuth2Generic" # Devise-specific config option Gitlab uses to find renamed strategy
58
+ }
59
+ }
60
+ ]
61
+ ````
62
+
63
+ Now if you visit `http://yourserver/auth/oauth2_generic` (or `/auth/Satorix` for the custom name example), you should be directed to log in with your OAuth2 server.
64
+
65
+ ## Configuration Options
66
+
67
+ Details about the available configuration options are provided as comments in [the OAuth2Generic class](lib/omniauth/strategies/oauth2_generic.rb).
68
+
69
+ Configuration options for this gem are:
70
+
71
+ * **client_options** - A Hash containing options for configuring the OAuth client to point to the right URLs
72
+ * **user_response_structure** - A Hash containing paths to various attributes of the user in the response that your OAuth server returns from the `user_info_url` specified in the `client_options`.
73
+ * **root_path** - An Array containing each key in the path to the node that contains the user attributes (i.e. `['data', 'attributes']` for a JsonAPI-formatted response)
74
+ * **id_path** - A String containing the name, or Array containing the keys in the path to the node that contains the user's ID (i.e. `['data', 'id']` for a JsonAPI-formatted response). Default: `'id'` (string values are assumed to be relative to the `root_path`)
75
+ * **attributes** - A Hash containing [standard Omniauth user attributes](https://github.com/omniauth/omniauth/wiki/auth-hash-schema#schema-10-and-later) and the names/paths to them in the response, if not the standard names (this hash defaults to looking for the standard names under the specified `root_path`)
76
+
77
+ **Note:** The entire raw response will also be returned in the `['extra']['raw_info']` field of the OmniAuth auth hash, regardless of the value of this option.
78
+ * **redirect_url** - The URL the client will be directed to after authentication. Defaults to `http://yourserver/auth/oauth2_generic/callback`
79
+
80
+ **Note:** Your OAuth server may restrict redirects to a specific list of URLs.
81
+ * **name** - A String. If set, this changes the name of the strategy used in the URLs and sometimes other places (the login button in Gitlab, for instance)
82
+
83
+ The hash options have default values for all keys, and your provided configuration is merged into the default, so you do not have to re-specify nested default options (although you will need to provide at least `site` and `user_info_url` in `client_options`, unless you want to use the default/example gitlab.com configuration).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/satorix"
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
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,2 @@
1
+ require "omniauth-oauth2-generic/version"
2
+ require "omniauth/strategies/oauth2_generic"
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module OAuth2Generic
3
+ VERSION = "0.2.2"
4
+ end
5
+ end
@@ -0,0 +1,73 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class OAuth2Generic < OmniAuth::Strategies::OAuth2
6
+ option :name, 'oauth2_generic'
7
+
8
+ option :client_options, { # Defaults are set for GitLab example implementation
9
+ site: 'https://gitlab.com', # The URL for your OAuth 2 server
10
+ user_info_url: '/api/v3/user', # The endpoint on your OAuth 2 server that provides user info for the current user
11
+ authorize_url: '/oauth/authorize', # The authorization endpoint for your OAuth server
12
+ token_url: '/oauth/token' # The token request endpoint for your OAuth server
13
+ }
14
+
15
+ option :user_response_structure, { # info about the structure of the response from the oauth server's user_info_url (specified above)
16
+ root_path: [], # The default path to the user attributes (i.e. ['data', 'attributes'])
17
+ id_path: 'id', # The name or path to the user ID (i.e. ['data', 'id]'). Scalars are considered relative to `root_path`, Arrays are absolute paths.
18
+ attributes: { # Alternate paths or names for any attributes that don't match the default
19
+ name: 'name', # Scalars are treated as relative (i.e. 'username' would point to response['data']['attributes']['username'], given a root_path of ['data', 'attributes'])
20
+ email: 'email', # Arrays are treated as absolute paths (i.e. ['included', 'contacts', 0, 'email'] would point to response['included']['contacts'][0]['email'], regardless of root_path)
21
+ nickname: 'nickname',
22
+ first_name: 'first_name',
23
+ last_name: 'last_name',
24
+ location: 'location',
25
+ description: 'description',
26
+ image: 'image',
27
+ phone: 'phone',
28
+ urls: 'urls'
29
+ }
30
+ }
31
+
32
+ option :redirect_url
33
+
34
+ uid do
35
+ fetch_user_info(user_paths[:id_path]).to_s
36
+ end
37
+
38
+ info do
39
+ user_paths[:attributes].inject({}) do |user_hash, (field, path)|
40
+ value = fetch_user_info(path)
41
+ user_hash[field] = value if value
42
+ user_hash
43
+ end
44
+ end
45
+
46
+ extra do
47
+ { raw_info: raw_info }
48
+ end
49
+
50
+ def raw_info
51
+ @raw_info ||= access_token.get(options.client_options[:user_info_url]).parsed
52
+ end
53
+
54
+ private
55
+
56
+ def user_paths
57
+ options.user_response_structure
58
+ end
59
+
60
+ def fetch_user_info(path)
61
+ return nil unless path
62
+ full_path = path.is_a?(Array) ? path : Array(user_paths[:root_path]) + [path]
63
+ full_path.inject(raw_info) { |info, key| info[key] rescue nil }
64
+ end
65
+
66
+ def callback_url
67
+ options.redirect_url || (full_host + script_name + callback_path)
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ OmniAuth.config.add_camelization 'oauth2_generic', 'OAuth2Generic'
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-oauth2-generic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-oauth2-generic"
8
+ spec.version = Omniauth::OAuth2Generic::VERSION
9
+ spec.authors = ["Joe Marty"]
10
+ spec.email = ["jmarty@iexposure.com"]
11
+
12
+ spec.summary = %q{Generic, Configurable OmniAuth Strategy for OAuth2 providers}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://gitlab.com/satorix/omniauth-oauth2-generic"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "omniauth-oauth2", "~> 1.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.13"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.1"
29
+ spec.add_development_dependency "rack-test"
30
+ spec.add_development_dependency "webmock"
31
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-oauth2-generic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Joe Marty
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-16 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.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.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: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Generic, Configurable OmniAuth Strategy for OAuth2 providers
98
+ email:
99
+ - jmarty@iexposure.com
100
+ executables:
101
+ - console
102
+ - setup
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - Gemfile
109
+ - LICENSE.md
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/omniauth-oauth2-generic.rb
115
+ - lib/omniauth-oauth2-generic/version.rb
116
+ - lib/omniauth/strategies/oauth2_generic.rb
117
+ - omniauth-oauth2-generic.gemspec
118
+ homepage: https://gitlab.com/satorix/omniauth-oauth2-generic
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.5.1
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Generic, Configurable OmniAuth Strategy for OAuth2 providers
142
+ test_files: []