Skip to content

Commit 1d4e7f5

Browse files
committed
Remove unneeded files, use user from app, add developer mode, add csrf dependency, update readme
1 parent 0eaf7b3 commit 1d4e7f5

File tree

22 files changed

+62
-465
lines changed

22 files changed

+62
-465
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This gem provides an easy way to generate new (Devise) sessions for members of a
55
If a user is signing in with GitHub and they are a (public) member of the configured GitHub organization, they will be allowed in.
66

77
## Environment Variables
8+
9+
### GitHub Login
10+
811
Make sure you configure your ENV variables to use Github authentication.
912

1013
```
@@ -33,6 +36,11 @@ Once you create the app and generate credentials for it, make sure you add them
3336
GITHUB_APP_ID=xxxxxxxxxxxxxxxxxxxx
3437
GITHUB_APP_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
3538
```
39+
40+
### Developer Login
41+
42+
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+
3644
## Getting Started
3745

3846
- Add these lines to your application's Gemfile:
@@ -42,6 +50,7 @@ gem 'ombu_labs-auth'
4250
```
4351

4452
- And then execute:
53+
4554
```bash
4655
$ bundle
4756
```
@@ -63,10 +72,28 @@ mount OmbuLabs::Auth::Engine, at: '/', as: 'ombu_labs_auth'
6372

6473
- Add the Devise authentication helper to your private objects controllers
6574

66-
```
75+
```rb
6776
before_action :authenticate_user!
6877
```
6978

79+
- Include the `OmbuLabsAuthenticable` concern in the authenticable model
80+
81+
```rb
82+
class User < ApplicationRecord
83+
include OmbuLabsAuthenticable
84+
...
85+
end
86+
```
87+
88+
- Tell `OmbuLabs::Auth` the class name for the authenticable model
89+
90+
```rb
91+
# config/initializers/ombu_labs-auth.rb
92+
OmbuLabs::Auth.user_class = 'User'
93+
```
94+
95+
### TODO: create a rails template to do all the previous steps automatically
96+
7097
## Caveats
7198

7299
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 +105,5 @@ Have a fix for a problem you've been running into or an idea for a new feature y
78105
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.
79106

80107
## License
108+
81109
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

app/assets/config/ombu_labs_auth_manifest.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/assets/images/ombu_labs/auth/.keep

Whitespace-only changes.

app/assets/stylesheets/ombu_labs/auth/application.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/controllers/ombu_labs/auth/callbacks_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def github
1212
member_logins = organization_members.map { |member| member["login"] }
1313

1414
if username.in?(member_logins)
15-
@user = User.from_omniauth(request.env["omniauth.auth"])
15+
@user = OmbuLabs::Auth.user_class.from_omniauth(request.env["omniauth.auth"])
1616
sign_in_and_redirect @user
1717
else
1818
flash[:error] = "This application is only available to members of #{organization_name}."
@@ -21,7 +21,7 @@ def github
2121
end
2222

2323
def developer
24-
@user = User.from_omniauth(request.env["omniauth.auth"])
24+
@user = OmbuLabs::Auth.user_class.from_omniauth(request.env["omniauth.auth"])
2525
sign_in_and_redirect @user
2626
end
2727

app/helpers/ombu_labs/auth/application_helper.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/jobs/ombu_labs/auth/application_job.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/mailers/ombu_labs/auth/application_mailer.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

app/models/concerns/.keep

Whitespace-only changes.
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
module OmbuLabs::Auth
2-
class User < ApplicationRecord
3-
self.table_name = "users"
1+
require "active_support/concern"
42

3+
module OmbuLabsAuthenticable
4+
extend ActiveSupport::Concern
5+
6+
included do
57
# Include default devise modules. Others available are:
68
# :confirmable, :lockable, :timeoutable
79
devise :database_authenticatable, :registerable,
810
:recoverable, :rememberable, :trackable,
911
:validatable, :omniauthable
10-
11-
def self.from_omniauth(auth)
12+
end
13+
14+
class_methods do
15+
def from_omniauth(auth)
1216
user_attributes = {
1317
email: auth.info.email,
1418
name: auth.info.name,
@@ -17,4 +21,4 @@ def self.from_omniauth(auth)
1721
where(provider: auth.provider, uid: auth.uid).first_or_create.tap { |user| user.update(user_attributes) }
1822
end
1923
end
20-
end
24+
end

0 commit comments

Comments
 (0)