omniauth-identity 1.1.1 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +81 -0
- data/CODE_OF_CONDUCT.md +133 -0
- data/LICENSE +22 -0
- data/README.md +238 -0
- data/lib/omniauth-identity.rb +2 -0
- data/lib/omniauth-identity/version.rb +3 -1
- data/lib/omniauth/identity.rb +3 -2
- data/lib/omniauth/identity/model.rb +17 -14
- data/lib/omniauth/identity/models/active_record.rb +4 -1
- data/lib/omniauth/identity/models/couch_potato.rb +3 -4
- data/lib/omniauth/identity/models/mongoid.rb +3 -7
- data/lib/omniauth/identity/models/{mongo_mapper.rb → no_brainer.rb} +6 -4
- data/lib/omniauth/identity/secure_password.rb +4 -4
- data/lib/omniauth/strategies/identity.rb +92 -39
- data/spec/omniauth/identity/model_spec.rb +60 -59
- data/spec/omniauth/identity/models/active_record_spec.rb +24 -8
- data/spec/omniauth/identity/models/couch_potato_spec.rb +17 -11
- data/spec/omniauth/identity/models/mongoid_spec.rb +23 -13
- data/spec/omniauth/identity/models/no_brainer_spec.rb +17 -0
- data/spec/omniauth/identity/secure_password_spec.rb +12 -12
- data/spec/omniauth/strategies/identity_spec.rb +178 -67
- data/spec/spec_helper.rb +20 -6
- metadata +75 -128
- data/.gitignore +0 -4
- data/.rspec +0 -2
- data/Gemfile +0 -11
- data/Gemfile.lock +0 -179
- data/Guardfile +0 -10
- data/README.markdown +0 -202
- data/Rakefile +0 -9
- data/lib/omniauth/identity/models/data_mapper.rb +0 -32
- data/omniauth-identity.gemspec +0 -32
- data/spec/omniauth/identity/models/data_mapper_spec.rb +0 -22
- data/spec/omniauth/identity/models/mongo_mapper_spec.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 629d1327cd3aa697de7139825ca429e8829886526da60aa233937643a56caf54
|
4
|
+
data.tar.gz: f8fa65f35a26646fcec82b86208da5a511e7639be3388997ede74e0b8df98ca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35d08b45518df49d12131b94fdd26110448161809153f782f709369f85488a30dda1bc2fc38121e19beda06c048bf1c8db5b2f901540ab10133bd52925cfe941
|
7
|
+
data.tar.gz: dc462e3a8e3733565d2d660bcf6495460e77376469f2cab70d140bff22a07c5f63b0fb3b09b94774956f1c9f47f67f2cbffdcf797e653cc112f31460a26b004a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
|
6
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
7
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
8
|
+
|
9
|
+
## [Unreleased]
|
10
|
+
|
11
|
+
## [3.0.3] - 2021-02-14
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Add option `:on_validation`, which can be used to add a Captcha
|
16
|
+
- See [example here](https://github.com/omniauth/omniauth-identity/pull/86#issue-63225122)
|
17
|
+
- Add support for nobrainer, an ORM for RethinkDB
|
18
|
+
- Validation error message on invalid registration form submission
|
19
|
+
|
20
|
+
### Removed
|
21
|
+
|
22
|
+
- ruby-head build... simply too slow
|
23
|
+
|
24
|
+
## [3.0.2] - 2021-02-14
|
25
|
+
|
26
|
+
### Fixed
|
27
|
+
|
28
|
+
- Github Actions CI Build for Ruby 2.4, 3.0 and ruby-head
|
29
|
+
- Updated copyright
|
30
|
+
- Code style cleanup
|
31
|
+
- Added Code Climate "Quality"
|
32
|
+
- Updated Readme
|
33
|
+
|
34
|
+
## [3.0.1] - 2021-02-14
|
35
|
+
|
36
|
+
### Fixed
|
37
|
+
|
38
|
+
- Github Actions CI Build for various Rubies
|
39
|
+
|
40
|
+
## [3.0] - 2021-02-13
|
41
|
+
|
42
|
+
### Added
|
43
|
+
|
44
|
+
- Compatibility with Ruby 3
|
45
|
+
- Add option `:enable_login` to bypass OmniAuth disabling of GET method (default `true`)
|
46
|
+
- NOTE: This restores compatibility between this gem and the current, core, omniauth gem!
|
47
|
+
- README updates, including a rename to README.md
|
48
|
+
- CODE_OF_CONDUCT.md using v2
|
49
|
+
- Rubocop
|
50
|
+
- Github Actions for Continuous Integration
|
51
|
+
- Minimum Ruby version = 2.4
|
52
|
+
- Automatically adds "provider" => "identity" when "provider" column is detected
|
53
|
+
- Documentation in README.md
|
54
|
+
|
55
|
+
### Removed
|
56
|
+
|
57
|
+
- Support for Rubies < 2.4
|
58
|
+
- Support for DataMapper, which died long ago.
|
59
|
+
- Unwanted git artifacts
|
60
|
+
|
61
|
+
## [2.0] - 2020-09-01
|
62
|
+
|
63
|
+
### Added
|
64
|
+
|
65
|
+
- CHANGELOG to maintain a history of changes.
|
66
|
+
- Include mongoid-rspec gem.
|
67
|
+
|
68
|
+
### Changed
|
69
|
+
|
70
|
+
- Fix failing Specs
|
71
|
+
- Update Spec syntax to RSpec 3
|
72
|
+
- Fix deprecation Warnings
|
73
|
+
- Updated mongoid_spec.rb to leverage mongoid-rspec features.
|
74
|
+
- Fix security warning about missing secret in session cookie.
|
75
|
+
- Dependency version limits so that the most up-to-date gem dependencies are used. (rspec 3+, mongo 2+, mongoid 7+, rake 13+, rack 2+, json 2+)
|
76
|
+
- Updated copyright information.
|
77
|
+
- Updated MongoMapper section of README to reflect its discontinued support.
|
78
|
+
|
79
|
+
### Removed
|
80
|
+
- Gemfile.lock file
|
81
|
+
- MongoMapper support; unable to satisfy dependencies of both MongoMapper and Mongoig now that MongoMapper is no longer actively maintained.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
|
2
|
+
# Contributor Covenant Code of Conduct
|
3
|
+
|
4
|
+
## Our Pledge
|
5
|
+
|
6
|
+
We as members, contributors, and leaders pledge to make participation in our
|
7
|
+
community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
9
|
+
identity and expression, level of experience, education, socio-economic status,
|
10
|
+
nationality, personal appearance, race, religion, or sexual identity
|
11
|
+
and orientation.
|
12
|
+
|
13
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
14
|
+
diverse, inclusive, and healthy community.
|
15
|
+
|
16
|
+
## Our Standards
|
17
|
+
|
18
|
+
Examples of behavior that contributes to a positive environment for our
|
19
|
+
community include:
|
20
|
+
|
21
|
+
* Demonstrating empathy and kindness toward other people
|
22
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
23
|
+
* Giving and gracefully accepting constructive feedback
|
24
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
25
|
+
and learning from the experience
|
26
|
+
* Focusing on what is best not just for us as individuals, but for the
|
27
|
+
overall community
|
28
|
+
|
29
|
+
Examples of unacceptable behavior include:
|
30
|
+
|
31
|
+
* The use of sexualized language or imagery, and sexual attention or
|
32
|
+
advances of any kind
|
33
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
34
|
+
* Public or private harassment
|
35
|
+
* Publishing others' private information, such as a physical or email
|
36
|
+
address, without their explicit permission
|
37
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
38
|
+
professional setting
|
39
|
+
|
40
|
+
## Enforcement Responsibilities
|
41
|
+
|
42
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
43
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
44
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
45
|
+
or harmful.
|
46
|
+
|
47
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
48
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
49
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
50
|
+
decisions when appropriate.
|
51
|
+
|
52
|
+
## Scope
|
53
|
+
|
54
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
55
|
+
an individual is officially representing the community in public spaces.
|
56
|
+
Examples of representing our community include using an official e-mail address,
|
57
|
+
posting via an official social media account, or acting as an appointed
|
58
|
+
representative at an online or offline event.
|
59
|
+
|
60
|
+
## Enforcement
|
61
|
+
|
62
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
63
|
+
reported to the community leaders responsible for enforcement at
|
64
|
+
[INSERT CONTACT METHOD].
|
65
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
66
|
+
|
67
|
+
All community leaders are obligated to respect the privacy and security of the
|
68
|
+
reporter of any incident.
|
69
|
+
|
70
|
+
## Enforcement Guidelines
|
71
|
+
|
72
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
73
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
74
|
+
|
75
|
+
### 1. Correction
|
76
|
+
|
77
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
78
|
+
unprofessional or unwelcome in the community.
|
79
|
+
|
80
|
+
**Consequence**: A private, written warning from community leaders, providing
|
81
|
+
clarity around the nature of the violation and an explanation of why the
|
82
|
+
behavior was inappropriate. A public apology may be requested.
|
83
|
+
|
84
|
+
### 2. Warning
|
85
|
+
|
86
|
+
**Community Impact**: A violation through a single incident or series
|
87
|
+
of actions.
|
88
|
+
|
89
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
90
|
+
interaction with the people involved, including unsolicited interaction with
|
91
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
92
|
+
includes avoiding interactions in community spaces as well as external channels
|
93
|
+
like social media. Violating these terms may lead to a temporary or
|
94
|
+
permanent ban.
|
95
|
+
|
96
|
+
### 3. Temporary Ban
|
97
|
+
|
98
|
+
**Community Impact**: A serious violation of community standards, including
|
99
|
+
sustained inappropriate behavior.
|
100
|
+
|
101
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
102
|
+
communication with the community for a specified period of time. No public or
|
103
|
+
private interaction with the people involved, including unsolicited interaction
|
104
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
105
|
+
Violating these terms may lead to a permanent ban.
|
106
|
+
|
107
|
+
### 4. Permanent Ban
|
108
|
+
|
109
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
110
|
+
standards, including sustained inappropriate behavior, harassment of an
|
111
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
112
|
+
|
113
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
114
|
+
the community.
|
115
|
+
|
116
|
+
## Attribution
|
117
|
+
|
118
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
119
|
+
version 2.0, available at
|
120
|
+
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
121
|
+
|
122
|
+
Community Impact Guidelines were inspired by
|
123
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
124
|
+
|
125
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
126
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
127
|
+
at [https://www.contributor-covenant.org/translations][translations].
|
128
|
+
|
129
|
+
[homepage]: https://www.contributor-covenant.org
|
130
|
+
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
131
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
132
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
133
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2021 OmniAuth-Identity Maintainers
|
2
|
+
Copyright (c) 2020 Peter Boling, Andrew Roberts, and Jellybooks Ltd.
|
3
|
+
Copyright (c) 2010-2015 Michael Bleigh and Intridea, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
# OmniAuth Identity
|
2
|
+
|
3
|
+
[![Version](https://img.shields.io/gem/v/omniauth-identity.svg)](https://rubygems.org/gems/omniauth-identity)
|
4
|
+
[![Depfu](https://badges.depfu.com/badges/6c9b45362951b872127f9e46d39bed76/count.svg)](https://depfu.com/github/omniauth/omniauth-identity?project_id=22381)
|
5
|
+
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fomniauth%2Fomniauth-identity%2Fbadge&style=flat)](https://actions-badge.atrox.dev/omniauth/omniauth-identity/goto)
|
6
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/621d6211cb2e0959ce00/maintainability)](https://codeclimate.com/github/omniauth/omniauth-identity/maintainability)
|
7
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/621d6211cb2e0959ce00/test_coverage)](https://codeclimate.com/github/omniauth/omniauth-identity/test_coverage)
|
8
|
+
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
|
9
|
+
[![Open Source Helpers](https://www.codetriage.com/omniauth/omniauth-identity/badges/users.svg)](https://www.codetriage.com/omniauth/omniauth-identity)
|
10
|
+
[![Downloads Rank](https://img.shields.io/gem/rd/omniauth-identity.svg)](https://rubygems.org/gems/omniauth-identity)
|
11
|
+
|
12
|
+
The OmniAuth Identity gem provides a way for applications to utilize a
|
13
|
+
traditional login/password based authentication system without the need
|
14
|
+
to give up the simple authentication flow provided by OmniAuth. Identity
|
15
|
+
is designed on purpose to be as featureless as possible: it provides the
|
16
|
+
basic construct for user management and then gets out of the way.
|
17
|
+
|
18
|
+
## Compatibility
|
19
|
+
|
20
|
+
This gem is compatible with, as of Feb 2021, version 3:
|
21
|
+
|
22
|
+
* Latest released version of omniauth, v2.0.2
|
23
|
+
* Ruby 2.4, 2.5, 2.6, 2.7, 3.0, ruby-head
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
To acquire the latest release from RubyGems add the following to your `Gemfile`:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'omniauth-identity'
|
31
|
+
```
|
32
|
+
|
33
|
+
If the git repository has new commits not yet in an official release, simply specify the repo instead:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'omniauth-identity', git: 'https://github.com/intridea/omniauth-identity.git'
|
37
|
+
```
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
This can be a bit hard to understand the first time. Luckily, Ryan Bates made
|
42
|
+
a [Railscast](http://railscasts.com/episodes/304-omniauth-identity) about it!
|
43
|
+
|
44
|
+
You use `omniauth-identity` just like you would any other OmniAuth provider: as a
|
45
|
+
Rack middleware. In rails, this would be created by an initializer, such as
|
46
|
+
`config/initializers/omniauth.rb`. The basic setup for a email/password authentication would look something like this:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
use OmniAuth::Builder do
|
50
|
+
provider :identity, #mandatory: tells OA that the Identity strategy is being used
|
51
|
+
model: Identity, # optional: specifies the name of the "Identity" model. Defaults to "Identity"
|
52
|
+
fields: %i[email custom1 custom2] # optional: list of custom fields that are in the model's table
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Next, you need to create a model (called `Identity` by default, or specified
|
57
|
+
with `:model` argument above) that will be able to persist the information
|
58
|
+
provided by the user. Luckily for you, there are pre-built models for popular
|
59
|
+
ORMs that make this dead simple.
|
60
|
+
|
61
|
+
Once you've got an `Identity` persistence model and the strategy up and
|
62
|
+
running, you can point users to `/auth/identity` and it will request
|
63
|
+
that they log in or give them the opportunity to sign up for an account.
|
64
|
+
Once they have authenticated with their identity, OmniAuth will call
|
65
|
+
through to `/auth/identity/callback` with the same kinds of information
|
66
|
+
it would had the user authenticated through an external provider.
|
67
|
+
|
68
|
+
**Note:** OmniAuth Identity is different from many other user authentication
|
69
|
+
systems in that it is *not* built to store authentication information in your primary
|
70
|
+
`User` model. Instead, the `Identity` model should be **associated** with your
|
71
|
+
`User` model giving you maximum flexibility to include other authentication
|
72
|
+
strategies such as Facebook, Twitter, etc.
|
73
|
+
|
74
|
+
### ActiveRecord
|
75
|
+
|
76
|
+
Just subclass `OmniAuth::Identity::Models::ActiveRecord` and provide fields
|
77
|
+
in the database for all of the fields you are using.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
class Identity < OmniAuth::Identity::Models::ActiveRecord
|
81
|
+
auth_key :email # optional: specifies the field within the model that will be used during the login process
|
82
|
+
# defaults to email, but may be username, uid, login, etc.
|
83
|
+
|
84
|
+
# Anything else you want!
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
### Mongoid
|
89
|
+
|
90
|
+
Include the `OmniAuth::Identity::Models::Mongoid` mixin and specify
|
91
|
+
fields that you will need.
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
class Identity
|
95
|
+
include Mongoid::Document
|
96
|
+
include OmniAuth::Identity::Models::Mongoid
|
97
|
+
|
98
|
+
field :email, type: String
|
99
|
+
field :name, type: String
|
100
|
+
field :password_digest, type: String
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
### CouchPotato
|
105
|
+
|
106
|
+
Include the `OmniAuth::Identity::Models::CouchPotatoModule` mixin and specify fields that you will need.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
class Identity
|
110
|
+
include CouchPotato::Persistence
|
111
|
+
include OmniAuth::Identity::Models::CouchPotatoModule
|
112
|
+
|
113
|
+
property :email
|
114
|
+
property :password_digest
|
115
|
+
|
116
|
+
def self.where(search_hash)
|
117
|
+
CouchPotato.database.view(Identity.by_email(key: search_hash))
|
118
|
+
end
|
119
|
+
|
120
|
+
view :by_email, key: :email
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
### NoBrainer
|
125
|
+
|
126
|
+
[NoBrainer](http://nobrainer.io/) is an ORM for [RethinkDB](https://rethinkdb.com/).
|
127
|
+
|
128
|
+
Include the `OmniAuth::Identity::Models::NoBrainer` mixin and specify fields that you will need.
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
class Identity
|
132
|
+
include NoBrainer::Document
|
133
|
+
include OmniAuth::Identity::Models::NoBrainer
|
134
|
+
|
135
|
+
auth_key :email
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
### Ruby Object Mapper
|
140
|
+
|
141
|
+
Would love to add a mixin for the [Ruby Object Mapper (ROM)](https://rom-rb.org/) if anyone wants to work on it!
|
142
|
+
|
143
|
+
## Custom Auth Model
|
144
|
+
|
145
|
+
To use a class other than the default, specify the <tt>:model</tt> option to a
|
146
|
+
different class.
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
use OmniAuth::Builder do
|
150
|
+
provider :identity, fields: [:email], model: MyCustomClass
|
151
|
+
end
|
152
|
+
```
|
153
|
+
|
154
|
+
NOTE: In the above example, `MyCustomClass` must have a class method called `auth_key` that returns
|
155
|
+
the default (`email`) or custom `auth_key` to use.
|
156
|
+
|
157
|
+
## Customizing Registration Failure
|
158
|
+
|
159
|
+
To use your own custom registration form, create a form that POSTs to
|
160
|
+
`/auth/identity/register` with `password`, `password_confirmation`, and your
|
161
|
+
other fields.
|
162
|
+
|
163
|
+
```erb
|
164
|
+
<%= form_tag '/auth/identity/register' do |f| %>
|
165
|
+
<h1>Create an Account</h1>
|
166
|
+
<%= text_field_tag :email %>
|
167
|
+
<%= password_field_tag :password %>
|
168
|
+
<%= password_field_tag :password_confirmation %>
|
169
|
+
<%= submit_tag %>
|
170
|
+
<% end %>
|
171
|
+
```
|
172
|
+
|
173
|
+
Beware not to nest your form parameters within a namespace. This strategy
|
174
|
+
looks for the form parameters at the top level of the post params. If you are
|
175
|
+
using [simple\_form](https://github.com/plataformatec/simple_form), then you
|
176
|
+
can avoid the params nesting by specifying `:input_html`.
|
177
|
+
|
178
|
+
```erb
|
179
|
+
<%= simple_form_for @identity, :url => '/auth/identity/register' do |f| %>
|
180
|
+
<h1>Create an Account</h1>
|
181
|
+
<%# specify :input_html to avoid params nesting %>
|
182
|
+
<%= f.input :email, :input_html => {:name => 'email'} %>
|
183
|
+
<%= f.input :password, :as => 'password', :input_html => {:name => 'password'} %>
|
184
|
+
<%= f.input :password_confirmation, :label => "Confirm Password", :as => 'password', :input_html => {:name => 'password_confirmation'} %>
|
185
|
+
<button type='submit'>Sign Up</button>
|
186
|
+
<% end %>
|
187
|
+
```
|
188
|
+
|
189
|
+
Next you'll need to let OmniAuth know what action to call when a registration
|
190
|
+
fails. In your OmniAuth configuration, specify any valid rack endpoint in the
|
191
|
+
`:on_failed_registration` option.
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
use OmniAuth::Builder do
|
195
|
+
provider :identity,
|
196
|
+
fields: [:email],
|
197
|
+
on_failed_registration: UsersController.action(:new)
|
198
|
+
end
|
199
|
+
```
|
200
|
+
|
201
|
+
For more information on rack endpoints, check out [this
|
202
|
+
introduction](http://library.edgecase.com/Rails/2011/01/04/rails-routing-and-rack-endpoints.html)
|
203
|
+
and
|
204
|
+
[ActionController::Metal](http://rubydoc.info/docs/rails/ActionController/Metal)
|
205
|
+
|
206
|
+
## Customizing Locate Conditions
|
207
|
+
|
208
|
+
You can customize the way that matching records are found when authenticating.
|
209
|
+
For example, for a site with multiple domains, you may wish to scope the search
|
210
|
+
within a particular subdomain. To do so, add :locate_conditions to your config.
|
211
|
+
The default value is:
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
use OmniAuth::Builder do
|
215
|
+
provider :identity,
|
216
|
+
locate_conditions: ->(req) { { model.auth_key => req['auth_key'] } }
|
217
|
+
# ...
|
218
|
+
end
|
219
|
+
```
|
220
|
+
|
221
|
+
`locate_conditions` takes a `Proc` object, and must return a `Hash` object, which will be used
|
222
|
+
as the argument to the locate method for your ORM. The proc is evaluated in the
|
223
|
+
callback context, and has access to your `Identity` model (using `model`) and receives the request
|
224
|
+
object as a parameter. Note that `model.auth_key` defaults to `email`, but is also configurable.
|
225
|
+
|
226
|
+
Note: Be careful when customizing `locate_conditions`. The best way to modify the conditions is
|
227
|
+
to copy the default value, and then add to the hash. Removing the default condition will almost
|
228
|
+
always break things!
|
229
|
+
|
230
|
+
## License
|
231
|
+
|
232
|
+
MIT License. See LICENSE for details.
|
233
|
+
|
234
|
+
## Copyright
|
235
|
+
|
236
|
+
Copyright (c) 2021 OmniAuth-Identity Maintainers
|
237
|
+
Copyright (c) 2020 Peter Boling, Andrew Roberts, and Jellybooks Ltd.
|
238
|
+
Copyright (c) 2010-2015 Michael Bleigh, and Intridea, Inc.
|