authegy 0.0.2 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c939c8d171cedd6e8e7f41d1fb692321365a1f72996420b74a5e2250c81438be
4
- data.tar.gz: c02ed8a0ae4e9b88ee8de0131ea8cacb60f2724e5aacdc0f1af296ee8c48d3ed
3
+ metadata.gz: 2a7fdcc608fb168061d6b17fa23335ee534a0d0fa9b65cd542daf21a7c36b515
4
+ data.tar.gz: ed2ba96fd8a897153ab2c34879d00c231db2ca3b09dda6eb826505e24217d5ec
5
5
  SHA512:
6
- metadata.gz: 164ed0276e9bd154d3ffd05f3ea8630b3c82522bb083a87d5d27942015aa4c2aedd18c38afdb291183c9ef3801fffc775ab132387dd548c27050545efa4550d4
7
- data.tar.gz: 283427d912da0cda5e0cf9437ff74e8f9ed63806083fee9e9db6fadd1c3f255367339f558d18550b08b4505057d7071e1d29a5ee2d911832033715af1141313e
6
+ metadata.gz: 585350d7081f58a6122480eaff47e98f05ed233e3633e887d4b9c640c90bb917c913293e0d71301bb0575031abe1bb80441342beeab2f7fad7b5c8c295e8678e
7
+ data.tar.gz: c1e6c3bf0287abda69a78330755786a236f5ed06a70172d4212052713dacf4e0f0f810c7eb918796a307a46ea7d513b901db3fa3563fd7fa830503ad4971d23b
@@ -1,5 +1,14 @@
1
1
  # Authegy Changelog
2
2
 
3
+ ## Version 0.0.3
4
+
5
+ - Fixed User Signup
6
+ - Use router method 'authegy_routes' instead of 'devise_for'
7
+
8
+ ## Version 0.0.2
9
+
10
+ - Minor correction over the User model template
11
+
3
12
  ## Version 0.0.1
4
13
 
5
14
  - Initial Implementation
data/README.md CHANGED
@@ -1,43 +1,94 @@
1
1
  # Authegy
2
2
 
3
- The Authegy gem is a library that combines several useful ruby libraries to
4
- provide an opinionated authentication and role-based authorization models for
3
+ The Authegy gem is a library that combines several top-grade ruby libraries to
4
+ provide an opinionated authentication and role-based authorization solution for
5
5
  your rails apps.
6
6
 
7
- ## Installation
7
+ The following libraries are used as the base of Authegy:
8
+ - Devise
9
+ - Doorkeeper
10
+
11
+ These libraries are used following a particular set of rules:
12
+
13
+ - Only a single `User` class: whereas `devise` allows for multiple
14
+ "authenticatable" models, we're going use single class, to which we can assign
15
+ different roles instead.
16
+ - The "profile" user data - such as names, email, phone, etc. - is extracted
17
+ into a separate `Person` model. We actually can create `Person` records
18
+ without an associated user, enabling us to manage a "contact list".
19
+ - Roles added to a given person can be assigned either unlimited, or scoped to a
20
+ given "resource" object.
21
+ - The only way of giving access to an app's RESTAPI (where available) is through
22
+ an OAuth2 flow (i.e. access token, etc) - that's where Doorkeeper comes into
23
+ play. Given that our most common use case for RESTAPIs is to be consumed by
24
+ non-confidential apps (Single-page apps, mobile apps, etc), we're avoiding
25
+ other solutions such as Devise JWT, Devise Token Auth, etc.
26
+ - All OAuth2 (doorkeeper) apps will have an owner, and admin roles may be
27
+ given to other people to manage the apps.
28
+ - Restrictions coming from the OAuth2 access token permissions will be added to
29
+ those already in effect from roles for the token's resource owner.
30
+
31
+ ## Getting started
8
32
 
9
33
  Add this line to your application's Gemfile:
10
34
 
11
35
  ```ruby
12
- gem 'authegy'
36
+ gem 'authegy', '~> 0.0.2'
13
37
  ```
14
38
 
15
- And then execute:
39
+ Then run `bundle install`.
16
40
 
17
- $ bundle
41
+ Next, you'll need to run the generator:
18
42
 
19
- Or install it yourself as:
43
+ $ rails generate authegy:install
20
44
 
21
- $ gem install authegy
45
+ The install generator will run the install routines for the required libraries (
46
+ devise, etc), and will also generate the required models, database migration and
47
+ routes to start working with the authegy model.
22
48
 
23
- ## Usage
49
+ ### Model methods
24
50
 
25
- ### Basic Use Case: The User & Role models
51
+ There are several methods available to the `Person` and `User` models, and are
52
+ very similar to the methods found at other RBAC libraries:
26
53
 
27
- - Use only a single "User" class, with several roles associated to it - instead
28
- of having multiple "user" classes, which tend to have duplicated code &
29
- functionality between them.
30
- - Roles can also be optionally associated to different "Resource" models, so we
31
- can limit the authorization to certain objects. Examples:
32
- - "User 2" is an "Administrator" of "Website 2" (so he/she can change the
33
- Website 2's URL)
34
- - "User 3" is a "Procurement Manager" of "Company 4" (so he/she can place
35
- orders on behalf of the Company 4)
54
+ ```ruby
36
55
 
37
- ![Base Use Case](docs/use-cases/base-use-case.svg)
56
+ # Create a person:
57
+ example_person = Person.create first_name: 'Example', last_name: 'Person', email: 'first@example.com'
58
+
59
+ # Assign a role to this person - The role will be created if it doesn't exist:
60
+ example_person.assign_role :administrator
61
+
62
+ # Assign a user to this person - he/she will now have the ability to sign-in:
63
+ example_user = example_person.create_user! password: '123456'
64
+
65
+ # You can assign roles scoped to a particular resource:
66
+ example_person.assign_role :moderator, Discussion.last
38
67
 
68
+ # You can test if the person has a role:
69
+ example_person.has_role? :moderator, Discussion.last
39
70
 
71
+ # All the role management methods are available to the `User` model via method
72
+ # delegation:
73
+ example_user.assign_role :moderator, Discussion.first
74
+ example_user.has_role? :moderator, Discussion.first
75
+
76
+ ```
77
+
78
+ ## The Authegy model, in detail
79
+
80
+ ![Base Use Case](docs/use-cases/base-use-case.svg)
40
81
 
82
+ - We extracted the `User` fields not fundamental to the process of
83
+ authentication into the model `Person`. This allows us to also cover cases in
84
+ which we are asked to manage a "contact list", with people that either can
85
+ sign-in or not. Notice the `email` field is also moved to the `Person` model -
86
+ we provide the code required for Devise to look in the `people` table.
87
+ - The way we assign roles to a person is using the `RoleAssignment` model. This
88
+ model also allows us to optionally specify a `resource` to which the assigned
89
+ role will be limited (or scoped). Notice how the `RoleAssignment` is separated
90
+ from the actual `Role` model, achieving a higher level of database
91
+ normalization.
41
92
 
42
93
  ## Development
43
94
 
@@ -54,7 +105,7 @@ git commits and tags, and push the `.gem` file to
54
105
  ## Contributing
55
106
 
56
107
  Bug reports and pull requests are welcome on GitHub at
57
- https://github.com/vovimayhem/authegy. This project is intended to be a safe,
108
+ https://github.com/vovimayhem/authegy-gem. This project is intended to be a safe,
58
109
  welcoming space for collaboration, and contributors are expected to adhere to
59
110
  the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
60
111
 
@@ -65,6 +116,6 @@ The gem is available as open source under the terms of the
65
116
 
66
117
  ## Code of Conduct
67
118
 
68
- Everyone interacting in the A2 project’s codebases, issue trackers, chat rooms
69
- and mailing lists is expected to follow the
70
- [Code of Conduct](https://github.com/vovimayhem/authegy/blob/master/CODE_OF_CONDUCT.md).
119
+ Everyone interacting in the Authegy project’s codebases, issue trackers, chat
120
+ rooms and mailing lists is expected to follow the
121
+ [Code of Conduct](https://github.com/vovimayhem/authegy-gem/blob/master/CODE_OF_CONDUCT.md).
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'authegy/rails/routes'
4
+
1
5
  module Authegy
2
6
  class Engine < ::Rails::Engine
3
7
  isolate_namespace Authegy
@@ -15,8 +15,17 @@ module Authegy
15
15
  devise :database_authenticatable_with_person_email,
16
16
  :validatable_with_person_email
17
17
 
18
- belongs_to :person, inverse_of: :user, foreign_key: :id
19
- delegate :email, :email=, :name, to: :person, allow_nil: true
18
+ belongs_to :person,
19
+ class_name: '::Person',
20
+ inverse_of: :user,
21
+ foreign_key: :id
22
+
23
+ delegate :email, :name, to: :person, allow_nil: true
24
+
25
+ def email=(value)
26
+ return person.email = value if person.present?
27
+ build_person(email: value).email
28
+ end
20
29
 
21
30
  delegate :assigned_roles, :assign_role, :has_role?, :has_any_role?,
22
31
  :remove_role, :role_assignments, to: :person
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module ActionDispatch
3
+ module Routing
4
+ class Mapper
5
+ def authegy_routes(options = {})
6
+ # Remove the keys that would interfere with the authegy way:
7
+ options.extract! :class_name, # We'll only use 'User'
8
+ :path, # All devise paths available from root
9
+ :singular # No 'resource name' required
10
+
11
+ default_path_names = { sign_in: 'sign-in', sign_out: 'sign-out' }
12
+ options.reverse_merge! path: '/', path_names: default_path_names
13
+
14
+ devise_for :users, options
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Authegy
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
@@ -19,11 +19,7 @@ class InstallGenerator < Rails::Generators::Base
19
19
  generate 'authegy:models People'
20
20
  end
21
21
 
22
- def add_devise_routes
23
- route <<~STRING
24
- devise_for :users,
25
- path: '/',
26
- path_names: { sign_in: 'sign-in', sign_out: 'sign-out' }
27
- STRING
22
+ def add_autegy_routes
23
+ route 'authegy_routes'
28
24
  end
29
25
  end
@@ -10,8 +10,8 @@ class CreateAuthegyModelTables < ActiveRecord::Migration<%= migration_version %>
10
10
 
11
11
  def create_people_table
12
12
  create_table :people do |t|
13
- t.string :first_name, null: false
14
- t.string :last_name, null: false
13
+ t.string :first_name
14
+ t.string :last_name
15
15
  t.string :email, index: { unique: true }
16
16
 
17
17
  # Feel free to add additional fields, such as 'nickname', etc:
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authegy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Quintanilla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-02 00:00:00.000000000 Z
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -140,6 +140,7 @@ files:
140
140
  - lib/authegy/models/role.rb
141
141
  - lib/authegy/models/role_assignment.rb
142
142
  - lib/authegy/models/user.rb
143
+ - lib/authegy/rails/routes.rb
143
144
  - lib/authegy/version.rb
144
145
  - lib/devise/models/database_authenticatable_with_person_email.rb
145
146
  - lib/devise/models/validatable_with_person_email.rb