knock-oauth2_code_verifier 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +43 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +158 -0
- data/Rakefile +6 -0
- data/app/controllers/knock/oauth2_code_verifier/application_controller.rb +7 -0
- data/app/controllers/knock/oauth2_code_verifier/auth_token_controller.rb +66 -0
- data/bin/console +14 -0
- data/bin/rails +14 -0
- data/bin/setup +8 -0
- data/config/routes.rb +2 -0
- data/knock-oauth2_code_verifier.gemspec +47 -0
- data/lib/knock/oauth2_code_verifier.rb +23 -0
- data/lib/knock/oauth2_code_verifier/configuration.rb +34 -0
- data/lib/knock/oauth2_code_verifier/engine.rb +7 -0
- data/lib/knock/oauth2_code_verifier/version.rb +7 -0
- data/lib/tasks/knock/oauth2_code_verifier_tasks.rake +4 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c65963c83357c644ae118da22b15e9011a2d206b127b888b13c8def0175ca12
|
4
|
+
data.tar.gz: 731c2e0e32f0da4b4ab9968adbd00257da7d26cf18b9b94a93828b9d0aca9f24
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ab7ea1aa6251a7c1417f0ffba4e026654d7b317c34ecc5a2c308d3b7cde375c52878470bad2e4b5bedb821b0d7253505efd59b57ddf4b03f18a0bd17f580dc8
|
7
|
+
data.tar.gz: c61954204e4dc435dba41cfab64ecce63f54bbccc9ffd068b884e747199231bd0cae2127e3264da3a4fdbe969153c56b41b9d18e64d4c9d20c905d6b441db549
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
|
4
|
+
Layout/LineLength:
|
5
|
+
Max: 80
|
6
|
+
|
7
|
+
Layout/MultilineMethodCallIndentation:
|
8
|
+
EnforcedStyle: indented
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Exclude:
|
12
|
+
- config/**/*
|
13
|
+
- spec/**/*
|
14
|
+
|
15
|
+
Lint/AmbiguousBlockAssociation:
|
16
|
+
Exclude:
|
17
|
+
- spec/**/*
|
18
|
+
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# Rails' autoloading will load modules so that there's no namespacing issue
|
23
|
+
# when using compact style
|
24
|
+
Style/ClassAndModuleChildren:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
# Having a comma at the end of a list of multi-line aruments avoids extra diffs
|
28
|
+
# on otherwise-untouched lines of code when adding a new item to the end
|
29
|
+
Style/TrailingCommaInArrayLiteral:
|
30
|
+
EnforcedStyleForMultiline: comma
|
31
|
+
Style/TrailingCommaInHashLiteral:
|
32
|
+
EnforcedStyleForMultiline: comma
|
33
|
+
Style/TrailingCommaInArguments:
|
34
|
+
EnforcedStyleForMultiline: comma
|
35
|
+
|
36
|
+
# https://anti-pattern.com/always-use-double-quoted-strings-in-ruby
|
37
|
+
Style/StringLiterals:
|
38
|
+
EnforcedStyle: double_quotes
|
39
|
+
|
40
|
+
# Defaults to 'e', which is an uncomminicative name by reek's rules
|
41
|
+
# See some discussion here: https://github.com/rubocop-hq/rubocop/pull/6460
|
42
|
+
Naming/RescuedExceptionsVariableName:
|
43
|
+
PreferredName: error
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
knock-oauth2_code_verifier
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.2
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at me@bmulholland.ca. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Brendan Mulholland
|
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,158 @@
|
|
1
|
+
# Backend provider of code verification for Oauth2 Authorization Code Request
|
2
|
+
|
3
|
+
Frontend libraries implement Oauth2 flows that authenticate the user with your
|
4
|
+
SPA, but are only part of the picture. If you're storing user data on a backend,
|
5
|
+
you'll need to authenticate them on both the frontend and the backend. That's
|
6
|
+
what Oauth2 Authorization Code Request does, with PKCE thrown in for added
|
7
|
+
security. This gem provides the backend authorization needed, taking in a
|
8
|
+
verification request and logging the user in via JWT with Knock. If you're using
|
9
|
+
Vue/React/etc with a frontend authorization library like @nuxt/auth, and you're
|
10
|
+
running Rails in API mode for your backend, this gem completes the picture.
|
11
|
+
|
12
|
+
Suggestions for improvement, bugs, and PRs are very welcomed.
|
13
|
+
|
14
|
+
## Requirements
|
15
|
+
|
16
|
+
[knock](https://github.com/nsarno/knock) for JWT authentication
|
17
|
+
|
18
|
+
I'd be happy to split this into an independent gem if you want to use it for
|
19
|
+
another auth library; file an issue with that request if you want (matching
|
20
|
+
PR preferred, of course).
|
21
|
+
|
22
|
+
**Note: if you're using Rails 6, you may have to use the master branch:**
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# Gemfile
|
26
|
+
# See https://davidgay.org/programming/jwt-auth-rails-6-knock/
|
27
|
+
# and https://github.com/nsarno/knock/issues/250
|
28
|
+
gem "knock", github: "nsarno/knock", branch: "master",
|
29
|
+
ref: "9214cd027422df8dc31eb67c60032fbbf8fc100b"
|
30
|
+
```
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
gem 'knock-oauth2_code_verifier'
|
38
|
+
```
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
$ bundle install
|
43
|
+
|
44
|
+
Or install it yourself as:
|
45
|
+
|
46
|
+
$ gem install knock-oauth2_code_verifier
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
Set up the routes and controller:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
# config/routes.rb
|
54
|
+
post "auth_token/:provider", to: "auth_token#create"
|
55
|
+
```
|
56
|
+
|
57
|
+
And create the controller:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# app/controllers/auth_token_controller.rb
|
61
|
+
class AuthTokenController < Knock::Oauth2CodeVerifier::AuthTokenController
|
62
|
+
def create
|
63
|
+
# knock-oauth2_code_verifier exposes:
|
64
|
+
# access_token - the user's access token for the provider
|
65
|
+
# refresh_token - the user's refresh_token, when first registering (blank on
|
66
|
+
# login)
|
67
|
+
# user_info - hash of user's info, with keys :name, :email, and :raw
|
68
|
+
# :raw contains the raw info hash from the provider
|
69
|
+
|
70
|
+
# Your code to create and login user here
|
71
|
+
# e.g. user = User.find_or_create_by!(user_info[:email])
|
72
|
+
|
73
|
+
# Then return a JWT payload; auth_token provided by Knock
|
74
|
+
render json: { token: auth_token }, status: :created
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
And finally configure the gem (use providers as necessary; Google Oauth2 and
|
80
|
+
Microsoft Azure Active Directory [NOT the B2C flavour] shown as examples):
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# config/initializers/knock_oauth2_code_verifier.rb
|
84
|
+
Knock::Oauth2CodeVerifier.configure do |config|
|
85
|
+
# The first argument, provder name, is inferred from the request URL:
|
86
|
+
# e.g. POST /auth_token/google
|
87
|
+
config.add_provider(
|
88
|
+
:google,
|
89
|
+
Rails.application.credentials.google_app[:client_id],
|
90
|
+
Rails.application.credentials.google_app[:client_secret],
|
91
|
+
{
|
92
|
+
token_url: "https://accounts.google.com/o/oauth2/token",
|
93
|
+
userinfo_url: "https://www.googleapis.com/oauth2/v3/userinfo"
|
94
|
+
}
|
95
|
+
)
|
96
|
+
|
97
|
+
config.add_provider(
|
98
|
+
:microsoft365,
|
99
|
+
Rails.application.credentials.microsoft_app[:client_id],
|
100
|
+
Rails.application.credentials.microsoft_app[:client_secret],
|
101
|
+
{
|
102
|
+
token_url: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
|
103
|
+
userinfo_url: "https://graph.microsoft.com/v1.0/me"
|
104
|
+
}
|
105
|
+
)
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
Then you can set your client library to forward code challenges to POST
|
110
|
+
`/auth_token/:provider`, e.g. `/auth_token/microsoft365`. For @nuxt/auth, that
|
111
|
+
looks like:
|
112
|
+
|
113
|
+
```javascript
|
114
|
+
# nuxt.config.js
|
115
|
+
export default {
|
116
|
+
auth: {
|
117
|
+
strategies: {
|
118
|
+
google: {
|
119
|
+
endpoints: {
|
120
|
+
token: 'http://localhost:4000/auth_token/google'
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
```
|
127
|
+
|
128
|
+
## Development
|
129
|
+
|
130
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
131
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an
|
132
|
+
interactive prompt that will allow you to experiment.
|
133
|
+
|
134
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
135
|
+
release a new version, update the version number in `version.rb`, and then run
|
136
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
137
|
+
git commits and tags, and push the `.gem` file to
|
138
|
+
[rubygems.org](https://rubygems.org).
|
139
|
+
|
140
|
+
## Contributing
|
141
|
+
|
142
|
+
Bug reports and pull requests are welcome on GitHub at
|
143
|
+
https://github.com/recitalsoftware/knock-oauth2_code_verifier. This project is
|
144
|
+
intended to be a safe, welcoming space for collaboration, and contributors are
|
145
|
+
expected to adhere to the
|
146
|
+
[code of conduct](https://github.com/recitalsoftware/knock-oauth2_code_verifier/blob/master/CODE_OF_CONDUCT.md).
|
147
|
+
|
148
|
+
|
149
|
+
## License
|
150
|
+
|
151
|
+
The gem is available as open source under the terms of the
|
152
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
153
|
+
|
154
|
+
## Code of Conduct
|
155
|
+
|
156
|
+
Everyone interacting in the Knock::Oauth2CodeVerifier project's codebases, issue
|
157
|
+
trackers, chat rooms and mailing lists is expected to follow the
|
158
|
+
[code of conduct](https://github.com/recitalsoftware/knock-oauth2_code_verifier/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "oauth2"
|
4
|
+
|
5
|
+
module Knock
|
6
|
+
module Oauth2CodeVerifier
|
7
|
+
class AuthTokenController < Knock::AuthTokenController
|
8
|
+
# Knock provides a bunch of auth stuff for us, so we base on that
|
9
|
+
# controller, but we don't want their default auth method (we need to auth
|
10
|
+
# them via OAuth, not the default email/password check)
|
11
|
+
skip_before_action :authenticate
|
12
|
+
|
13
|
+
def create
|
14
|
+
raise "Implement #create in your controller"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def config
|
20
|
+
Knock::Oauth2CodeVerifier.configuration.for_provider(params[:provider])
|
21
|
+
end
|
22
|
+
|
23
|
+
def client
|
24
|
+
@client ||= OAuth2::Client.new(
|
25
|
+
config.client_id,
|
26
|
+
config.client_secret,
|
27
|
+
authorize_url: config.authorize_url,
|
28
|
+
token_url: config.token_url,
|
29
|
+
logger: Rails.logger,
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def access_token
|
34
|
+
@access_token ||= client
|
35
|
+
.auth_code
|
36
|
+
.get_token(
|
37
|
+
params[:code],
|
38
|
+
{
|
39
|
+
redirect_uri: params[:redirect_uri],
|
40
|
+
code_verifier: params[:code_verifier],
|
41
|
+
},
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def refresh_token
|
46
|
+
# Only set on the first auth, and perhaps if the access token expires?
|
47
|
+
# e.g. https://developers.google.com/identity/protocols/oauth2#expiration
|
48
|
+
access_token&.refresh_token
|
49
|
+
end
|
50
|
+
|
51
|
+
def user_info
|
52
|
+
return @user_info if @user_info
|
53
|
+
|
54
|
+
info = JSON.parse(access_token.get(config[:userinfo_url]).body)
|
55
|
+
|
56
|
+
@user_info = {
|
57
|
+
auth_provider: params[:provider],
|
58
|
+
name: info["name"] || info["displayName"],
|
59
|
+
email: info["email"] || info["mail"],
|
60
|
+
refresh_token: refresh_token,
|
61
|
+
raw_info: info,
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "knock/oauth2_code_verifier"
|
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__)
|
data/bin/rails
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/knock/oauth2_code_verifier/engine', __dir__)
|
7
|
+
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
require 'rails/all'
|
14
|
+
require 'rails/engine/commands'
|
data/bin/setup
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$:.push File.expand_path("lib", __dir__)
|
4
|
+
|
5
|
+
require "knock/oauth2_code_verifier/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "knock-oauth2_code_verifier"
|
9
|
+
spec.version = Knock::Oauth2CodeVerifier::VERSION
|
10
|
+
spec.authors = ["Brendan Mulholland"]
|
11
|
+
spec.email = ["brendan@recital.software"]
|
12
|
+
|
13
|
+
spec.summary = "Backend provider of code verification for OAuth2\
|
14
|
+
Authorization Code Request"
|
15
|
+
spec.description = "Frontend libraries implement OAuth2 flows that \
|
16
|
+
authenticate the user with your SPA, but are only part of the picture. If you're\
|
17
|
+
storing user data on a backend, you'll need to authenticate them on both the\
|
18
|
+
frontend and the backend. That's what Oauth2 Authorization Code Request does,\
|
19
|
+
with PKCE thrown in for added security. This gem provides the backend\
|
20
|
+
authorization needed, taking in a verification request and logging the user in\
|
21
|
+
via JWT with Knock. If you're using Vue/React/etc with a frontend authorization\
|
22
|
+
library like @nuxt/auth, and you're running Rails in API mode for your backend,\
|
23
|
+
this gem completes the picture."
|
24
|
+
spec.homepage = "https://github.com/recitalsoftware/knock-oauth2_code_verifier"
|
25
|
+
spec.license = "MIT"
|
26
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
27
|
+
|
28
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
29
|
+
|
30
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
31
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
32
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
33
|
+
|
34
|
+
# Specify which files should be added to the gem when it is released.
|
35
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
36
|
+
# into git.
|
37
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
38
|
+
`git ls-files -z`.split("\x0").reject { |f|
|
39
|
+
f.match(%r{^(test|spec|features)/})
|
40
|
+
}
|
41
|
+
end
|
42
|
+
spec.require_paths = %w[app lib]
|
43
|
+
|
44
|
+
spec.add_dependency "rails", ">= 5"
|
45
|
+
spec.add_dependency "knock", ">= 2.1.0"
|
46
|
+
spec.add_dependency "oauth2", ">= 1.4.0"
|
47
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "knock/oauth2_code_verifier/configuration"
|
4
|
+
require "knock/oauth2_code_verifier/engine"
|
5
|
+
require "knock/oauth2_code_verifier/version"
|
6
|
+
|
7
|
+
module Knock
|
8
|
+
module Oauth2CodeVerifier
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_writer :configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configuration
|
16
|
+
@configuration ||= Configuration.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
yield(configuration)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
module Knock
|
6
|
+
module Oauth2CodeVerifier
|
7
|
+
class Configuration
|
8
|
+
attr_accessor :providers
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@providers = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_provider(provider, client_id, client_secret, urls)
|
15
|
+
raise "provider is required" unless provider
|
16
|
+
raise "client ID for provider is required" unless client_id
|
17
|
+
raise "client secret for provider is required" unless client_secret
|
18
|
+
raise "URL for token is required" unless urls[:token_url]
|
19
|
+
raise "URL for user info is required" unless urls[:userinfo_url]
|
20
|
+
|
21
|
+
@providers[provider] = {
|
22
|
+
client_id: client_id,
|
23
|
+
client_secret: client_secret,
|
24
|
+
token_url: urls[:token_url],
|
25
|
+
userinfo_url: urls[:userinfo_url],
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def for_provider(provider)
|
30
|
+
OpenStruct.new(@providers[provider.to_sym])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knock-oauth2_code_verifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brendan Mulholland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: knock
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oauth2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.4.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.4.0
|
55
|
+
description: Frontend libraries implement OAuth2 flows that authenticate the user
|
56
|
+
with your SPA, but are only part of the picture. If you'restoring user data on a
|
57
|
+
backend, you'll need to authenticate them on both thefrontend and the backend. That's
|
58
|
+
what Oauth2 Authorization Code Request does,with PKCE thrown in for added security.
|
59
|
+
This gem provides the backendauthorization needed, taking in a verification request
|
60
|
+
and logging the user invia JWT with Knock. If you're using Vue/React/etc with a
|
61
|
+
frontend authorizationlibrary like @nuxt/auth, and you're running Rails in API mode
|
62
|
+
for your backend,this gem completes the picture.
|
63
|
+
email:
|
64
|
+
- brendan@recital.software
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- ".gitignore"
|
70
|
+
- ".rspec"
|
71
|
+
- ".rubocop.yml"
|
72
|
+
- ".ruby-gemset"
|
73
|
+
- ".ruby-version"
|
74
|
+
- ".travis.yml"
|
75
|
+
- CHANGELOG.md
|
76
|
+
- CODE_OF_CONDUCT.md
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- app/controllers/knock/oauth2_code_verifier/application_controller.rb
|
82
|
+
- app/controllers/knock/oauth2_code_verifier/auth_token_controller.rb
|
83
|
+
- bin/console
|
84
|
+
- bin/rails
|
85
|
+
- bin/setup
|
86
|
+
- config/routes.rb
|
87
|
+
- knock-oauth2_code_verifier.gemspec
|
88
|
+
- lib/knock/oauth2_code_verifier.rb
|
89
|
+
- lib/knock/oauth2_code_verifier/configuration.rb
|
90
|
+
- lib/knock/oauth2_code_verifier/engine.rb
|
91
|
+
- lib/knock/oauth2_code_verifier/version.rb
|
92
|
+
- lib/tasks/knock/oauth2_code_verifier_tasks.rake
|
93
|
+
homepage: https://github.com/recitalsoftware/knock-oauth2_code_verifier
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata:
|
97
|
+
allowed_push_host: https://rubygems.org/
|
98
|
+
homepage_uri: https://github.com/recitalsoftware/knock-oauth2_code_verifier
|
99
|
+
source_code_uri: https://github.com/recitalsoftware/knock-oauth2_code_verifier
|
100
|
+
changelog_uri: https://github.com/recitalsoftware/knock-oauth2_code_verifier/CHANGELOG.md
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- app
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.3.0
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubygems_version: 3.1.4
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Backend provider of code verification for OAuth2Authorization Code Request
|
121
|
+
test_files: []
|