capcoauth 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +82 -1
- data/lib/capcoauth/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0f67e3a83ec6473b07b2457266900eb0e27e395
|
4
|
+
data.tar.gz: b08ab8274f0602d1f3b1a09dabf04a1a2283df99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f838187c0c67626ab8a390de889ce6cdef44b1a0baf9bf4cca81d17012359d3058de45c3f6be92f25c93bc582a3062d96fe1cba2e8f1c993a8804402f64dc76d
|
7
|
+
data.tar.gz: 13ca517c867d28b3b376159a4872b12e887d72ffe363499ba90f52a13409077935deedebeaf483dd7c11f618a7c2bcd3cf7f9858dd204ae504f5c7ebfaa8941d
|
data/README.md
CHANGED
@@ -1,3 +1,84 @@
|
|
1
1
|
# capcoauth-gem
|
2
2
|
|
3
|
-
Ruby Gem for integrating with CapcOAuth
|
3
|
+
Ruby Gem for integrating a Rails project with CapcOAuth
|
4
|
+
|
5
|
+
Currently, this only supports session-based authentication, but can easily be adapted to accept bearer tokens if needed.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Add to your gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'capcoauth'
|
13
|
+
```
|
14
|
+
|
15
|
+
2. Run the following from your console to install the gem:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
3. Run the following from your console to install the initializer in `config/initializers/capcoauth.rb`:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
rails generate capcoauth:install
|
25
|
+
```
|
26
|
+
|
27
|
+
## Configure
|
28
|
+
|
29
|
+
### Enter your client_id and client_secret into initializer
|
30
|
+
|
31
|
+
You'll need to obtain an OAuth client ID and client secret for your application, which can then be entered into your
|
32
|
+
initializer in `config/initializers/capcoauth.rb`.
|
33
|
+
|
34
|
+
### Authorize your routes!
|
35
|
+
|
36
|
+
In your controllers, just call the helper method `verify_authorized!` for all protected resources. This is easiest done
|
37
|
+
by adding it as a before_action:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class ApplicationController < ActionController::Base
|
41
|
+
before_action :verify_authorized
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
You may exclude/include for specific actions:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class ApplicationController < ActionController::Base
|
49
|
+
before_action :verify_authorized, only: [:my_super_secret_action], except: [:my_publicly_accessible_action]
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
Or even skip it entirely for specific actions:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class PublicStuffController < ApplicationController
|
57
|
+
skip_before_action :verify_authorized
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
## How it works
|
62
|
+
|
63
|
+
The installation script will add `use_capcoauth` to your `routes.rb` file, which creates these routes for you:
|
64
|
+
|
65
|
+
```
|
66
|
+
Prefix Verb URI Pattern Controller#Action
|
67
|
+
auth_login GET /auth/login(.:format) capcoauth/login#show
|
68
|
+
auth_logout GET /auth/logout(.:format) capcoauth/logout#show
|
69
|
+
auth_callback GET /auth/callback(.:format) capcoauth/callback#show
|
70
|
+
```
|
71
|
+
|
72
|
+
These are very important, as they implement the core functionality of this gem. The `login` route will generate a
|
73
|
+
CapcOAuth authorization URL appropriate for your application, and redirect the user to it. Upon successful login and
|
74
|
+
authorization of your application, they will be redirected to the `callback` route, which will exchange their code with
|
75
|
+
an access token, and will store that and the user's ID in the session.
|
76
|
+
|
77
|
+
Verification of the access token happens when `verify_authorized!` is executed, which caches the success response for
|
78
|
+
whatever TTL value you set in your initializer. This saves time by preventing every request from calling home to
|
79
|
+
CapcOAuth for approval. This can be increased or decreased at your discretion, but should be kept to a relatively low
|
80
|
+
value.
|
81
|
+
|
82
|
+
## Bugs? Feature requests? Pull requests?
|
83
|
+
|
84
|
+
Email me or submit via issue/pull request.
|
data/lib/capcoauth/version.rb
CHANGED