You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To avoid the need of a GitHub application setup (useful for local development or Heroku Review Apps), the `developer` strategy can be enabled using setting a `SHOW_DEVELOPER_AUTH` variable with any non-blank value (`SHOW_DEVELOPER_AUTH=1` or `SHOW_DEVELOPER_AUTH=true` for example).
43
+
36
44
## Getting Started
37
45
38
-
- Add these lines to your application's Gemfile:
46
+
### Requirements
47
+
48
+
A `User`-like model that will be used for the authentication (`User`, `Admin`, `Client`, etc).
49
+
50
+
The database table for that model must have, at least, these fields:
51
+
52
+
```rb
53
+
create_table :clientsdo |t|
54
+
t.string :email, unique:true
55
+
t.string :provider
56
+
t.string :uid, unique:true
57
+
t.string :name
58
+
t.string :encrypted_password
59
+
end
60
+
```
61
+
62
+
### Installation
63
+
64
+
- Add this line to your application's Gemfile:
39
65
40
66
```ruby
41
67
gem 'ombu_labs-auth'
42
68
```
43
69
44
70
- And then execute:
71
+
45
72
```bash
46
73
$ bundle
47
74
```
@@ -61,12 +88,67 @@ mount OmbuLabs::Auth::Engine, at: '/', as: 'ombu_labs_auth'
61
88
</div>
62
89
```
63
90
91
+
> This will default to a basic HTML page included in this gem. To customize this view, check [this section](#customizing-sign-in-page)
92
+
64
93
- Add the Devise authentication helper to your private objects controllers
65
94
66
-
```
95
+
```rb
67
96
before_action :authenticate_user!
68
97
```
69
98
99
+
- Include the `OmbuLabsAuthenticable` concern in the authenticable model
100
+
101
+
```rb
102
+
classAdmin < ApplicationRecord
103
+
includeOmbuLabsAuthenticable
104
+
...
105
+
end
106
+
```
107
+
108
+
- Tell `OmbuLabs::Auth` the user class name and table for the authenticable model
109
+
110
+
```rb
111
+
# config/initializers/ombu_labs-auth.rb
112
+
OmbuLabs::Auth.user_class_name ="Admin"# defaults to "User" if not set
113
+
OmbuLabs::Auth.users_table_name =:admins# defaults to :users if not set
114
+
```
115
+
116
+
> You can skip this step if the table is called `users` and the model is called `User`
117
+
118
+
- Log Out action
119
+
120
+
A link to `ombu_labs_auth.destroy_user_session_path` with method `DELETE` can be used. If rails-ujs is not available, a `button_to` can be used.
### TODO: create a rails template to do all the previous steps automatically
127
+
128
+
## Customizing sign in page
129
+
130
+
The gem provides a basic html template to select the authentication method. To customize it, create a view at `views/devise/session/new.html.erb` and a layout at `views/layouts/devise.html.erb`.
131
+
132
+
Include this snippet in the `new` view:
133
+
134
+
```
135
+
<%- Devise.omniauth_providers.each do |provider| %>
136
+
<%= button_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(OmbuLabs::Auth.user_class, provider), method: :post %><br />
137
+
<% end -%>
138
+
```
139
+
140
+
To use a `link_to` helper instead of a `button_to` helper to, rails-ujs is needed to support making a `POST` request with link tags. Then, replace with:
141
+
142
+
```
143
+
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(OmbuLabs::Auth.user_class, provider), method: :post, data: { 'turbo-method' => :post } %><br />
144
+
```
145
+
146
+
> If this intermediate page is not needed, the button/link to `omniauth_authorize_path` can be used directly.
147
+
148
+
## Running tests
149
+
150
+
Run `rake app:test:all` to run all tests and `rake app:test` to skip system tests.
151
+
70
152
## Caveats
71
153
72
154
Please be aware this gem is a mountable engine which depends on Devise, and it's not possible to mount it multiple times. Refer to their Wiki for more on the issue - https://github.com/heartcombo/devise/wiki/How-To:-Use-devise-inside-a-mountable-engine
@@ -78,4 +160,5 @@ Have a fix for a problem you've been running into or an idea for a new feature y
78
160
Take a look at the [Contributing document](https://github.com/fastruby/ombu_labs-auth/blob/main/CONTRIBUTING.md) for instructions to set up the repo on your machine and create a good Pull Request.
79
161
80
162
## License
163
+
81
164
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
0 commit comments