capcoauth 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +82 -1
  3. data/lib/capcoauth/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 044a5432917dc3dcf800b665080c2ff0e68ef7ee
4
- data.tar.gz: ed80f5118d7afcadfed3629b0f7359d8e3e7598e
3
+ metadata.gz: a0f67e3a83ec6473b07b2457266900eb0e27e395
4
+ data.tar.gz: b08ab8274f0602d1f3b1a09dabf04a1a2283df99
5
5
  SHA512:
6
- metadata.gz: df69c54c64cb65e34351f91f688d8e35d28dd8ef4e3afcf19b9d29e4c7b72c0d540b585c3af7d9c361f25150c47999a0bfc14438f5f3e5cbfbbea703d0464beb
7
- data.tar.gz: 75161dc7136c45a3092a2c9bcfcf3d5b9b98c3b34c8d73212b9bbc16bc0d2ed24cb5b8d96172b5022640a71508d5cba9d294610234e15769abdc58f460ba4b83
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.
@@ -1,3 +1,3 @@
1
1
  module Capcoauth
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capcoauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Robertson