devise_jwt_auth 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +13 -0
- data/README.md +99 -0
- data/Rakefile +42 -0
- data/app/controllers/devise_jwt_auth/application_controller.rb +80 -0
- data/app/controllers/devise_jwt_auth/concerns/resource_finder.rb +44 -0
- data/app/controllers/devise_jwt_auth/concerns/set_user_by_jwt_token.rb +111 -0
- data/app/controllers/devise_jwt_auth/confirmations_controller.rb +88 -0
- data/app/controllers/devise_jwt_auth/omniauth_callbacks_controller.rb +291 -0
- data/app/controllers/devise_jwt_auth/passwords_controller.rb +217 -0
- data/app/controllers/devise_jwt_auth/refresh_token_controller.rb +41 -0
- data/app/controllers/devise_jwt_auth/registrations_controller.rb +203 -0
- data/app/controllers/devise_jwt_auth/sessions_controller.rb +131 -0
- data/app/controllers/devise_jwt_auth/unlocks_controller.rb +99 -0
- data/app/models/devise_jwt_auth/concerns/active_record_support.rb +16 -0
- data/app/models/devise_jwt_auth/concerns/confirmable_support.rb +27 -0
- data/app/models/devise_jwt_auth/concerns/mongoid_support.rb +19 -0
- data/app/models/devise_jwt_auth/concerns/tokens_serialization.rb +19 -0
- data/app/models/devise_jwt_auth/concerns/user.rb +117 -0
- data/app/models/devise_jwt_auth/concerns/user_omniauth_callbacks.rb +28 -0
- data/app/validators/devise_jwt_auth_email_validator.rb +23 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise_jwt_auth/omniauth_external_window.html.erb +38 -0
- data/config/locales/da-DK.yml +52 -0
- data/config/locales/de.yml +51 -0
- data/config/locales/en.yml +57 -0
- data/config/locales/es.yml +51 -0
- data/config/locales/fr.yml +51 -0
- data/config/locales/he.yml +52 -0
- data/config/locales/it.yml +48 -0
- data/config/locales/ja.yml +48 -0
- data/config/locales/ko.yml +51 -0
- data/config/locales/nl.yml +32 -0
- data/config/locales/pl.yml +50 -0
- data/config/locales/pt-BR.yml +48 -0
- data/config/locales/pt.yml +50 -0
- data/config/locales/ro.yml +48 -0
- data/config/locales/ru.yml +52 -0
- data/config/locales/sq.yml +48 -0
- data/config/locales/sv.yml +52 -0
- data/config/locales/uk.yml +61 -0
- data/config/locales/vi.yml +52 -0
- data/config/locales/zh-CN.yml +48 -0
- data/config/locales/zh-HK.yml +50 -0
- data/config/locales/zh-TW.yml +50 -0
- data/lib/devise_jwt_auth.rb +14 -0
- data/lib/devise_jwt_auth/blacklist.rb +2 -0
- data/lib/devise_jwt_auth/controllers/helpers.rb +161 -0
- data/lib/devise_jwt_auth/controllers/url_helpers.rb +10 -0
- data/lib/devise_jwt_auth/engine.rb +96 -0
- data/lib/devise_jwt_auth/errors.rb +8 -0
- data/lib/devise_jwt_auth/rails/routes.rb +118 -0
- data/lib/devise_jwt_auth/token_factory.rb +51 -0
- data/lib/devise_jwt_auth/url.rb +44 -0
- data/lib/devise_jwt_auth/version.rb +5 -0
- data/lib/generators/devise_jwt_auth/USAGE +31 -0
- data/lib/generators/devise_jwt_auth/install_generator.rb +91 -0
- data/lib/generators/devise_jwt_auth/install_generator_helpers.rb +98 -0
- data/lib/generators/devise_jwt_auth/install_mongoid_generator.rb +46 -0
- data/lib/generators/devise_jwt_auth/install_views_generator.rb +18 -0
- data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth.rb +74 -0
- data/lib/generators/devise_jwt_auth/templates/devise_jwt_auth_create_users.rb.erb +51 -0
- data/lib/generators/devise_jwt_auth/templates/user.rb.erb +9 -0
- data/lib/generators/devise_jwt_auth/templates/user_mongoid.rb.erb +56 -0
- data/lib/tasks/devise_token_auth_tasks.rake +6 -0
- data/test/controllers/custom/custom_confirmations_controller_test.rb +25 -0
- data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +33 -0
- data/test/controllers/custom/custom_passwords_controller_test.rb +79 -0
- data/test/controllers/custom/custom_refresh_token_controller_test.rb +36 -0
- data/test/controllers/custom/custom_registrations_controller_test.rb +59 -0
- data/test/controllers/custom/custom_sessions_controller_test.rb +39 -0
- data/test/controllers/demo_group_controller_test.rb +150 -0
- data/test/controllers/demo_mang_controller_test.rb +286 -0
- data/test/controllers/demo_user_controller_test.rb +650 -0
- data/test/controllers/devise_jwt_auth/confirmations_controller_test.rb +194 -0
- data/test/controllers/devise_jwt_auth/omniauth_callbacks_controller_test.rb +462 -0
- data/test/controllers/devise_jwt_auth/passwords_controller_test.rb +881 -0
- data/test/controllers/devise_jwt_auth/refresh_token_controller_test.rb +84 -0
- data/test/controllers/devise_jwt_auth/registrations_controller_test.rb +944 -0
- data/test/controllers/devise_jwt_auth/sessions_controller_test.rb +510 -0
- data/test/controllers/devise_jwt_auth/unlocks_controller_test.rb +197 -0
- data/test/controllers/overrides/confirmations_controller_test.rb +47 -0
- data/test/controllers/overrides/omniauth_callbacks_controller_test.rb +53 -0
- data/test/controllers/overrides/passwords_controller_test.rb +65 -0
- data/test/controllers/overrides/refresh_token_controller_test.rb +37 -0
- data/test/controllers/overrides/registrations_controller_test.rb +47 -0
- data/test/controllers/overrides/sessions_controller_test.rb +35 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/app/active_record/confirmable_user.rb +11 -0
- data/test/dummy/app/active_record/lockable_user.rb +7 -0
- data/test/dummy/app/active_record/mang.rb +5 -0
- data/test/dummy/app/active_record/only_email_user.rb +7 -0
- data/test/dummy/app/active_record/scoped_user.rb +9 -0
- data/test/dummy/app/active_record/unconfirmable_user.rb +9 -0
- data/test/dummy/app/active_record/unregisterable_user.rb +9 -0
- data/test/dummy/app/active_record/user.rb +6 -0
- data/test/dummy/app/controllers/application_controller.rb +18 -0
- data/test/dummy/app/controllers/auth_origin_controller.rb +7 -0
- data/test/dummy/app/controllers/custom/confirmations_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +13 -0
- data/test/dummy/app/controllers/custom/passwords_controller.rb +39 -0
- data/test/dummy/app/controllers/custom/refresh_token_controller.rb +20 -0
- data/test/dummy/app/controllers/custom/registrations_controller.rb +39 -0
- data/test/dummy/app/controllers/custom/sessions_controller.rb +29 -0
- data/test/dummy/app/controllers/demo_group_controller.rb +15 -0
- data/test/dummy/app/controllers/demo_mang_controller.rb +14 -0
- data/test/dummy/app/controllers/demo_user_controller.rb +27 -0
- data/test/dummy/app/controllers/overrides/confirmations_controller.rb +37 -0
- data/test/dummy/app/controllers/overrides/omniauth_callbacks_controller.rb +16 -0
- data/test/dummy/app/controllers/overrides/passwords_controller.rb +45 -0
- data/test/dummy/app/controllers/overrides/refresh_token_controller.rb +22 -0
- data/test/dummy/app/controllers/overrides/registrations_controller.rb +29 -0
- data/test/dummy/app/controllers/overrides/sessions_controller.rb +36 -0
- data/test/dummy/app/helpers/application_helper.rb +1058 -0
- data/test/dummy/app/models/concerns/favorite_color.rb +19 -0
- data/test/dummy/app/mongoid/confirmable_user.rb +52 -0
- data/test/dummy/app/mongoid/lockable_user.rb +38 -0
- data/test/dummy/app/mongoid/mang.rb +46 -0
- data/test/dummy/app/mongoid/only_email_user.rb +33 -0
- data/test/dummy/app/mongoid/scoped_user.rb +50 -0
- data/test/dummy/app/mongoid/unconfirmable_user.rb +44 -0
- data/test/dummy/app/mongoid/unregisterable_user.rb +47 -0
- data/test/dummy/app/mongoid/user.rb +49 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +18 -0
- data/test/dummy/config/application.rb +48 -0
- data/test/dummy/config/application.yml.bk +0 -0
- data/test/dummy/config/boot.rb +11 -0
- data/test/dummy/config/environment.rb +7 -0
- data/test/dummy/config/environments/development.rb +46 -0
- data/test/dummy/config/environments/production.rb +84 -0
- data/test/dummy/config/environments/test.rb +50 -0
- data/test/dummy/config/initializers/assets.rb +10 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +9 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/devise.rb +290 -0
- data/test/dummy/config/initializers/devise_jwt_auth.rb +55 -0
- data/test/dummy/config/initializers/figaro.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/test/dummy/config/initializers/inflections.rb +18 -0
- data/test/dummy/config/initializers/mime_types.rb +6 -0
- data/test/dummy/config/initializers/omniauth.rb +11 -0
- data/test/dummy/config/initializers/session_store.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +16 -0
- data/test/dummy/config/routes.rb +57 -0
- data/test/dummy/config/spring.rb +3 -0
- data/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +58 -0
- data/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +57 -0
- data/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +8 -0
- data/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +7 -0
- data/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +55 -0
- data/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +56 -0
- data/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +56 -0
- data/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +56 -0
- data/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +56 -0
- data/test/dummy/db/migrate/20190924101113_devise_token_auth_create_confirmable_users.rb +49 -0
- data/test/dummy/db/schema.rb +198 -0
- data/test/dummy/lib/migration_database_helper.rb +43 -0
- data/test/dummy/tmp/generators/app/models/user.rb +9 -0
- data/test/dummy/tmp/generators/config/initializers/devise_jwt_auth.rb +74 -0
- data/test/dummy/tmp/generators/config/routes.rb +4 -0
- data/test/dummy/tmp/generators/db/migrate/20200206224309_devise_jwt_auth_create_users.rb +51 -0
- data/test/factories/users.rb +41 -0
- data/test/lib/devise_jwt_auth/blacklist_test.rb +11 -0
- data/test/lib/devise_jwt_auth/token_factory_test.rb +115 -0
- data/test/lib/devise_jwt_auth/url_test.rb +26 -0
- data/test/lib/generators/devise_jwt_auth/install_generator_test.rb +219 -0
- data/test/lib/generators/devise_jwt_auth/install_generator_with_namespace_test.rb +224 -0
- data/test/lib/generators/devise_jwt_auth/install_views_generator_test.rb +25 -0
- data/test/models/concerns/mongoid_support_test.rb +31 -0
- data/test/models/concerns/tokens_serialization_test.rb +72 -0
- data/test/models/confirmable_user_test.rb +35 -0
- data/test/models/only_email_user_test.rb +29 -0
- data/test/models/user_test.rb +110 -0
- data/test/support/controllers/routes.rb +43 -0
- data/test/test_helper.rb +91 -0
- metadata +503 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0517633f0e6ab6279f0c88ea33f0297b61ad94b9efa4b3db4d83befb21c0337a
|
4
|
+
data.tar.gz: 928947b0baddce870ee1562dec38641cff72660406974df8313dad02523b8482
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 883502bfa948b19aad5c25d9d79793e33bee14d2ad13656c6ba9a0e1ac7e6617b03075757831a50ea5747e1fdad2ed25ce0868a0707256569ae9af5e3e66e3e2
|
7
|
+
data.tar.gz: cba02b2f073b3466cb0b59d8c1be85117736928d6a4976c8183c16edfbdc8e12699ce9eec016a0d29a70cb49b8dd3a2124bb7f2e7eb76bb66c5d7202aadfc4a6
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
2
|
+
Version 2, December 2004
|
3
|
+
|
4
|
+
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
5
|
+
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
7
|
+
copies of this license document, and changing it is allowed as long
|
8
|
+
as the name is changed.
|
9
|
+
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
11
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
12
|
+
|
13
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Devise Token Auth
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/devise_jwt_auth.svg)](http://badge.fury.io/rb/devise_jwt_auth)
|
4
|
+
[![Build Status](https://travis-ci.org/lynndylanhurley/devise_jwt_auth.svg?branch=master)](https://travis-ci.org/lynndylanhurley/devise_jwt_auth)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/lynndylanhurley/devise_jwt_auth/badges/gpa.svg)](https://codeclimate.com/github/lynndylanhurley/devise_jwt_auth)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/lynndylanhurley/devise_jwt_auth/badges/coverage.svg)](https://codeclimate.com/github/lynndylanhurley/devise_jwt_auth/coverage)
|
7
|
+
[![Downloads](https://img.shields.io/gem/dt/devise_jwt_auth.svg)](https://rubygems.org/gems/devise_jwt_auth)
|
8
|
+
[![Backers on Open Collective](https://opencollective.com/devise_jwt_auth/backers/badge.svg)](#backers)
|
9
|
+
[![Sponsors on Open Collective](https://opencollective.com/devise_jwt_auth/sponsors/badge.svg)](#sponsors)
|
10
|
+
[![Join the chat at https://gitter.im/lynndylanhurley/devise_jwt_auth](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/lynndylanhurley/devise_jwt_auth?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
11
|
+
|
12
|
+
Simple, multi-client and secure token-based authentication for Rails.
|
13
|
+
|
14
|
+
If you're building SPA or a mobile app, and you want authentication, you need tokens, not cookies.
|
15
|
+
This gem refreshes the tokens on each request, and expires them in a short time, so the app is secure.
|
16
|
+
Also, it maintains a session for each client/device, so you can have as many sessions as you want.
|
17
|
+
|
18
|
+
## Main features
|
19
|
+
|
20
|
+
* Seamless integration with:
|
21
|
+
* [ng-token-auth](https://github.com/lynndylanhurley/ng-token-auth) for [AngularJS](https://github.com/angular/angular.js)
|
22
|
+
* [Angular-Token](https://github.com/neroniaky/angular-token) for [Angular](https://github.com/angular/angular)
|
23
|
+
* [redux-token-auth](https://github.com/kylecorbelli/redux-token-auth) for [React with Redux](https://github.com/reactjs/react-redux)
|
24
|
+
* [jToker](https://github.com/lynndylanhurley/j-toker) for [jQuery](https://jquery.com/)
|
25
|
+
* Oauth2 authentication using [OmniAuth](https://github.com/intridea/omniauth).
|
26
|
+
* Email authentication using [Devise](https://github.com/plataformatec/devise), including:
|
27
|
+
* User registration, update and deletion
|
28
|
+
* Login and logout
|
29
|
+
* Password reset, account confirmation
|
30
|
+
* Support for [multiple user models](./docs/usage/multiple_models.md).
|
31
|
+
* It is [secure](docs/security.md).
|
32
|
+
|
33
|
+
This project leverages the following gems:
|
34
|
+
|
35
|
+
* [Devise](https://github.com/plataformatec/devise)
|
36
|
+
* [OmniAuth](https://github.com/intridea/omniauth)
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
Add the following to your `Gemfile`:
|
41
|
+
|
42
|
+
~~~ruby
|
43
|
+
gem 'devise_jwt_auth'
|
44
|
+
~~~
|
45
|
+
|
46
|
+
Then install the gem using bundle:
|
47
|
+
|
48
|
+
~~~bash
|
49
|
+
bundle install
|
50
|
+
~~~
|
51
|
+
|
52
|
+
## [Docs](https://devise-token-auth.gitbook.io/devise-token-auth)
|
53
|
+
|
54
|
+
## Need help?
|
55
|
+
|
56
|
+
Please use [StackOverflow](https://stackoverflow.com/questions/tagged/devise-token-auth) for help requests and how-to questions.
|
57
|
+
|
58
|
+
Please open GitHub issues for bugs and enhancements only, not general help requests. Please search previous issues (and Google and StackOverflow) before creating a new issue.
|
59
|
+
|
60
|
+
Please read the [issue template](https://github.com/lynndylanhurley/devise_jwt_auth/blob/master/.github/ISSUE_TEMPLATE.md) before posting issues.
|
61
|
+
|
62
|
+
## [FAQ](docs/faq.md)
|
63
|
+
|
64
|
+
## Contributors wanted!
|
65
|
+
|
66
|
+
See our [Contribution Guidelines](https://github.com/lynndylanhurley/devise_jwt_auth/blob/master/.github/CONTRIBUTING.md). Feel free to submit pull requests, review pull requests, or review open issues. If you'd like to get in contact, [Zach Feldman](https://github.com/zachfeldman) has been wrangling this effort, you can reach him with his name @gmail. Further discussion of this in [this issue](https://github.com/lynndylanhurley/devise_jwt_auth/issues/969).
|
67
|
+
|
68
|
+
We have some bounties for some issues, [check them out](https://github.com/lynndylanhurley/devise_jwt_auth/issues?q=is%3Aopen+is%3Aissue+label%3Abounty)!
|
69
|
+
|
70
|
+
## Live Demos
|
71
|
+
|
72
|
+
[Here is a demo](http://ng-token-auth-demo.herokuapp.com/) of this app running with the [ng-token-auth](https://github.com/lynndylanhurley/ng-token-auth) module and [AngularJS](https://github.com/angular/angular.js).
|
73
|
+
|
74
|
+
[Here is a demo](https://stackblitz.com/github/neroniaky/angular-token) of this app running with the [Angular-Token](https://github.com/neroniaky/angular-token) service and [Angular](https://github.com/angular/angular).
|
75
|
+
|
76
|
+
[Here is a demo](https://j-toker-demo.herokuapp.com/) of this app using the [jToker](https://github.com/lynndylanhurley/j-toker) plugin and [React](http://facebook.github.io/react/).
|
77
|
+
|
78
|
+
The fully configured api used in these demos can be found [here](https://github.com/lynndylanhurley/devise_jwt_auth_demo).
|
79
|
+
|
80
|
+
|
81
|
+
## Contributors
|
82
|
+
|
83
|
+
<a href="graphs/contributors"><img src="https://opencollective.com/devise_jwt_auth/contributors.svg?width=890&button=false" /></a>
|
84
|
+
|
85
|
+
## Backers
|
86
|
+
|
87
|
+
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/devise_jwt_auth#backer)]
|
88
|
+
|
89
|
+
[![](https://opencollective.com/devise_jwt_auth/backers.svg?width=890)](https://opencollective.com/devise_jwt_auth#backers)
|
90
|
+
|
91
|
+
|
92
|
+
## Sponsors
|
93
|
+
|
94
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/devise_jwt_auth#sponsor)]
|
95
|
+
|
96
|
+
[![](https://opencollective.com/devise_jwt_auth/sponsor/0/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/0/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/1/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/1/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/2/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/2/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/3/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/3/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/4/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/4/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/5/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/5/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/6/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/6/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/7/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/7/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/8/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/8/website) [![](https://opencollective.com/devise_jwt_auth/sponsor/9/avatar.svg)](https://opencollective.com/devise_jwt_auth/sponsor/9/website)
|
97
|
+
|
98
|
+
## License
|
99
|
+
This project uses the WTFPL
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'DeviseJwtAuth'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.rdoc')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
20
|
+
load 'rails/tasks/engine.rake'
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
t.warning = false
|
32
|
+
end
|
33
|
+
|
34
|
+
task default: :test
|
35
|
+
|
36
|
+
require 'rubocop/rake_task'
|
37
|
+
|
38
|
+
desc 'Run RuboCop'
|
39
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
40
|
+
task.formatters = %w[fuubar offenses worst]
|
41
|
+
task.fail_on_error = false # don't abort rake on failure
|
42
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviseJwtAuth
|
4
|
+
class ApplicationController < DeviseController
|
5
|
+
# include DeviseJwtAuth::Concerns::SetUserByToken
|
6
|
+
include DeviseJwtAuth::Concerns::SetUserByJwtToken
|
7
|
+
|
8
|
+
def resource_data(opts = {})
|
9
|
+
response_data = opts[:resource_json] || @resource.as_json
|
10
|
+
response_data['type'] = @resource.class.name.parameterize if json_api?
|
11
|
+
response_data
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_errors
|
15
|
+
@resource.errors.to_hash.merge(full_messages: @resource.errors.full_messages)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def blacklisted_redirect_url?(redirect_url)
|
21
|
+
DeviseJwtAuth.redirect_whitelist && !DeviseJwtAuth::Url.whitelisted?(redirect_url)
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_redirect_headers(access_token, client, redirect_header_options = {})
|
25
|
+
{
|
26
|
+
# DeviseJwtAuth.headers_names[:"access-token"] => access_token,
|
27
|
+
# DeviseJwtAuth.headers_names[:"client"] => client,
|
28
|
+
:config => params[:config],
|
29
|
+
|
30
|
+
# Legacy parameters which may be removed in a future release.
|
31
|
+
# Consider using "client" and "access-token" in client code.
|
32
|
+
# See: github.com/lynndylanhurley/devise_jwt_auth/issues/993
|
33
|
+
# :client_id => client,
|
34
|
+
:token => access_token
|
35
|
+
}.merge(redirect_header_options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def params_for_resource(resource)
|
39
|
+
devise_parameter_sanitizer.instance_values['permitted'][resource].each do |type|
|
40
|
+
params[type.to_s] ||= request.headers[type.to_s] unless request.headers[type.to_s].nil?
|
41
|
+
end
|
42
|
+
devise_parameter_sanitizer.instance_values['permitted'][resource]
|
43
|
+
end
|
44
|
+
|
45
|
+
def resource_class(m = nil)
|
46
|
+
if m
|
47
|
+
mapping = Devise.mappings[m]
|
48
|
+
else
|
49
|
+
mapping = Devise.mappings[resource_name] || Devise.mappings.values.first
|
50
|
+
end
|
51
|
+
|
52
|
+
mapping.to
|
53
|
+
end
|
54
|
+
|
55
|
+
def json_api?
|
56
|
+
return false unless defined?(ActiveModel::Serializer)
|
57
|
+
return ActiveModel::Serializer.setup do |config|
|
58
|
+
config.adapter == :json_api
|
59
|
+
end if ActiveModel::Serializer.respond_to?(:setup)
|
60
|
+
ActiveModelSerializers.config.adapter == :json_api
|
61
|
+
end
|
62
|
+
|
63
|
+
def recoverable_enabled?
|
64
|
+
resource_class.devise_modules.include?(:recoverable)
|
65
|
+
end
|
66
|
+
|
67
|
+
def confirmable_enabled?
|
68
|
+
resource_class.devise_modules.include?(:confirmable)
|
69
|
+
end
|
70
|
+
|
71
|
+
def render_error(status, message, data = nil)
|
72
|
+
response = {
|
73
|
+
success: false,
|
74
|
+
errors: [message]
|
75
|
+
}
|
76
|
+
response = response.merge(data) if data
|
77
|
+
render json: response, status: status
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviseJwtAuth::Concerns::ResourceFinder
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include DeviseJwtAuth::Controllers::Helpers
|
6
|
+
|
7
|
+
def get_case_insensitive_field_from_resource_params(field)
|
8
|
+
# honor Devise configuration for case_insensitive keys
|
9
|
+
q_value = resource_params[field.to_sym]
|
10
|
+
|
11
|
+
if resource_class.case_insensitive_keys.include?(field.to_sym)
|
12
|
+
q_value.downcase!
|
13
|
+
end
|
14
|
+
|
15
|
+
if resource_class.strip_whitespace_keys.include?(field.to_sym)
|
16
|
+
q_value.strip!
|
17
|
+
end
|
18
|
+
|
19
|
+
q_value
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_resource(field, value)
|
23
|
+
@resource = if resource_class.try(:connection_config).try(:[], :adapter).try(:include?, 'mysql')
|
24
|
+
# fix for mysql default case insensitivity
|
25
|
+
resource_class.where("BINARY #{field} = ? AND provider= ?", value, provider).first
|
26
|
+
else
|
27
|
+
resource_class.dta_find_by(field => value, 'provider' => provider)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def resource_class(m = nil)
|
32
|
+
mapping = if m
|
33
|
+
Devise.mappings[m]
|
34
|
+
else
|
35
|
+
Devise.mappings[resource_name] || Devise.mappings.values.first
|
36
|
+
end
|
37
|
+
|
38
|
+
mapping.to
|
39
|
+
end
|
40
|
+
|
41
|
+
def provider
|
42
|
+
'email'
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviseJwtAuth::Concerns::SetUserByJwtToken
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include DeviseJwtAuth::Concerns::ResourceFinder
|
6
|
+
|
7
|
+
included do
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def set_user_by_token(mapping = nil)
|
14
|
+
# determine target authentication class
|
15
|
+
rc = resource_class(mapping)
|
16
|
+
|
17
|
+
# no default user defined
|
18
|
+
return unless rc
|
19
|
+
|
20
|
+
# check for an existing user, authenticated via warden/devise, if enabled
|
21
|
+
if DeviseJwtAuth.enable_standard_devise_support
|
22
|
+
devise_warden_user = warden.user(rc.to_s.underscore.to_sym)
|
23
|
+
@resource = devise_warden_user if devise_warden_user
|
24
|
+
end
|
25
|
+
|
26
|
+
# user has already been found and authenticated
|
27
|
+
return @resource if @resource && @resource.is_a?(rc)
|
28
|
+
|
29
|
+
# TODO: Look for the access token in an 'Authentication' header
|
30
|
+
token = request.headers[DeviseJwtAuth.access_token_name]
|
31
|
+
return unless token
|
32
|
+
|
33
|
+
payload = DeviseJwtAuth::TokenFactory.decode_access_token(token)
|
34
|
+
return if payload.empty?
|
35
|
+
return if payload && payload['sub'].blank?
|
36
|
+
uid = payload['sub']
|
37
|
+
|
38
|
+
# mitigate timing attacks by finding by uid instead of auth token
|
39
|
+
user = uid && rc.dta_find_by(uid: uid)
|
40
|
+
scope = rc.to_s.underscore.to_sym
|
41
|
+
|
42
|
+
if user
|
43
|
+
# sign_in with bypass: true will be deprecated in the next version of Devise
|
44
|
+
if respond_to?(:bypass_sign_in) && DeviseJwtAuth.bypass_sign_in
|
45
|
+
bypass_sign_in(user, scope: scope)
|
46
|
+
else
|
47
|
+
sign_in(scope, user, store: false, event: :fetch, bypass: DeviseJwtAuth.bypass_sign_in)
|
48
|
+
end
|
49
|
+
return @resource = user
|
50
|
+
else
|
51
|
+
# zero all values previously set values
|
52
|
+
return @resource = nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_user_by_refresh_token(mapping = nil)
|
57
|
+
# determine target authentication class
|
58
|
+
rc = resource_class(mapping)
|
59
|
+
|
60
|
+
# no default user defined
|
61
|
+
return unless rc
|
62
|
+
|
63
|
+
# check for an existing user, authenticated via warden/devise, if enabled
|
64
|
+
if DeviseJwtAuth.enable_standard_devise_support
|
65
|
+
devise_warden_user = warden.user(rc.to_s.underscore.to_sym)
|
66
|
+
@resource = devise_warden_user if devise_warden_user
|
67
|
+
end
|
68
|
+
|
69
|
+
# user has already been found and authenticated
|
70
|
+
return @resource if @resource && @resource.is_a?(rc)
|
71
|
+
|
72
|
+
token = request.cookies[DeviseJwtAuth.refresh_token_name]
|
73
|
+
|
74
|
+
return unless token
|
75
|
+
|
76
|
+
payload = DeviseJwtAuth::TokenFactory.decode_refresh_token(token)
|
77
|
+
return if payload.empty?
|
78
|
+
return if payload && payload['sub'].blank?
|
79
|
+
uid = payload['sub']
|
80
|
+
|
81
|
+
# mitigate timing attacks by finding by uid instead of auth token
|
82
|
+
user = uid && rc.dta_find_by(uid: uid)
|
83
|
+
scope = rc.to_s.underscore.to_sym
|
84
|
+
|
85
|
+
if user
|
86
|
+
# sign_in with bypass: true will be deprecated in the next version of Devise
|
87
|
+
if respond_to?(:bypass_sign_in) && DeviseJwtAuth.bypass_sign_in
|
88
|
+
bypass_sign_in(user, scope: scope)
|
89
|
+
else
|
90
|
+
sign_in(scope, user, store: false, event: :fetch, bypass: DeviseJwtAuth.bypass_sign_in)
|
91
|
+
end
|
92
|
+
return @resource = user
|
93
|
+
else
|
94
|
+
# zero all values previously set values
|
95
|
+
return @resource = nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def update_refresh_token_cookie
|
101
|
+
response.set_cookie(DeviseJwtAuth.refresh_token_name,
|
102
|
+
value: @resource.create_refresh_token,
|
103
|
+
path: '/auth/refresh_token', # TODO: Use configured auth path
|
104
|
+
expires: Time.zone.now + DeviseJwtAuth.refresh_token_lifespan,
|
105
|
+
httponly: true,
|
106
|
+
secure: Rails.env.production?
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeviseJwtAuth
|
4
|
+
class ConfirmationsController < DeviseJwtAuth::ApplicationController
|
5
|
+
|
6
|
+
def show
|
7
|
+
@resource = resource_class.confirm_by_token(resource_params[:confirmation_token])
|
8
|
+
|
9
|
+
if @resource.errors.empty?
|
10
|
+
yield @resource if block_given?
|
11
|
+
|
12
|
+
redirect_header_options = { account_confirmation_success: true }
|
13
|
+
|
14
|
+
if signed_in?(resource_name)
|
15
|
+
# token = signed_in_resource.create_token
|
16
|
+
|
17
|
+
# redirect_headers = build_redirect_headers(token.token,
|
18
|
+
# token.client,
|
19
|
+
# redirect_header_options)
|
20
|
+
|
21
|
+
redirect_headers = signed_in_resource.create_named_token_pair.
|
22
|
+
merge(redirect_header_options)
|
23
|
+
|
24
|
+
# TODO: add a refresh token cookie in the response.
|
25
|
+
update_refresh_token_cookie
|
26
|
+
|
27
|
+
#redirect_to_link = signed_in_resource.build_auth_url(redirect_url, redirect_headers)
|
28
|
+
redirect_to_link = DeviseJwtAuth::Url.generate(redirect_url, redirect_headers)
|
29
|
+
else
|
30
|
+
redirect_to_link = DeviseJwtAuth::Url.generate(redirect_url, redirect_header_options)
|
31
|
+
end
|
32
|
+
|
33
|
+
redirect_to(redirect_to_link)
|
34
|
+
else
|
35
|
+
raise ActionController::RoutingError, 'Not Found'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create
|
40
|
+
return render_create_error_missing_email if resource_params[:email].blank?
|
41
|
+
|
42
|
+
@email = get_case_insensitive_field_from_resource_params(:email)
|
43
|
+
|
44
|
+
@resource = resource_class.dta_find_by(uid: @email, provider: provider)
|
45
|
+
|
46
|
+
return render_not_found_error unless @resource
|
47
|
+
|
48
|
+
@resource.send_confirmation_instructions({
|
49
|
+
redirect_url: redirect_url,
|
50
|
+
client_config: resource_params[:config_name]
|
51
|
+
})
|
52
|
+
|
53
|
+
return render_create_success
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def render_create_error_missing_email
|
59
|
+
render_error(401, I18n.t('devise_jwt_auth.confirmations.missing_email'))
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_create_success
|
63
|
+
render json: {
|
64
|
+
success: true,
|
65
|
+
message: I18n.t('devise_jwt_auth.confirmations.sended', email: @email)
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def render_not_found_error
|
70
|
+
render_error(404, I18n.t('devise_jwt_auth.confirmations.user_not_found', email: @email))
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def resource_params
|
76
|
+
params.permit(:email, :confirmation_token, :config_name)
|
77
|
+
end
|
78
|
+
|
79
|
+
# give redirect value from params priority or fall back to default value if provided
|
80
|
+
def redirect_url
|
81
|
+
params.fetch(
|
82
|
+
:redirect_url,
|
83
|
+
DeviseJwtAuth.default_confirm_success_url
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|