knock 1.4.2 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +8 -8
  2. data/app/controllers/knock/application_controller.rb +1 -1
  3. data/app/controllers/knock/auth_token_controller.rb +32 -7
  4. data/app/model/knock/auth_token.rb +31 -7
  5. data/lib/generators/knock/token_controller_generator.rb +25 -0
  6. data/lib/generators/templates/entity_token_controller.rb.erb +2 -0
  7. data/lib/generators/templates/knock.rb +25 -3
  8. data/lib/knock.rb +7 -0
  9. data/lib/knock/authenticable.rb +45 -6
  10. data/lib/knock/version.rb +1 -1
  11. data/test/controllers/knock/auth_token_controller_test.rb +11 -0
  12. data/test/dummy/app/controllers/admin_protected_controller.rb +7 -0
  13. data/test/dummy/app/controllers/admin_token_controller.rb +2 -0
  14. data/test/dummy/app/controllers/composite_name_entity_protected_controller.rb +7 -0
  15. data/test/dummy/app/controllers/vendor_protected_controller.rb +11 -0
  16. data/test/dummy/app/controllers/vendor_token_controller.rb +2 -0
  17. data/test/dummy/app/models/admin.rb +16 -0
  18. data/test/dummy/app/models/composite_name_entity.rb +3 -0
  19. data/test/dummy/app/models/vendor.rb +3 -0
  20. data/test/dummy/config/initializers/knock.rb +10 -0
  21. data/test/dummy/config/routes.rb +8 -0
  22. data/test/dummy/db/migrate/20160519075733_create_admins.rb +10 -0
  23. data/test/dummy/db/migrate/20160522051816_create_vendors.rb +10 -0
  24. data/test/dummy/db/migrate/20160522181712_create_composite_name_entities.rb +10 -0
  25. data/test/dummy/db/schema.rb +22 -1
  26. data/test/dummy/db/test.sqlite3 +0 -0
  27. data/test/dummy/log/test.log +333 -91
  28. data/test/dummy/test/controllers/admin_protected_controller_test.rb +49 -0
  29. data/test/dummy/test/controllers/admin_token_controller_test.rb +22 -0
  30. data/test/dummy/test/controllers/composite_name_entity_protected_controller_test.rb +49 -0
  31. data/test/dummy/test/controllers/vendor_protected_controller_test.rb +55 -0
  32. data/test/dummy/test/controllers/vendor_token_controller_test.rb +22 -0
  33. data/test/dummy/test/models/admin_test.rb +7 -0
  34. data/test/dummy/test/models/vendor_test.rb +7 -0
  35. data/test/{dummy/test/fixtures/users.yml → fixtures/admins.yml} +1 -5
  36. data/test/fixtures/composite_name_entities.yml +5 -0
  37. data/test/fixtures/vendors.yml +5 -0
  38. data/test/generators/token_controller_generator_test.rb +31 -0
  39. data/test/model/knock/auth_token_test.rb +33 -9
  40. data/test/support/generators_test_helper.rb +9 -0
  41. data/test/test_helper.rb +9 -0
  42. data/test/tmp/app/controllers/admin_token_controller.rb +2 -0
  43. data/test/tmp/app/controllers/admin_user_token_controller.rb +2 -0
  44. data/test/tmp/app/controllers/user_admin_token_controller.rb +2 -0
  45. data/test/tmp/app/controllers/user_token_controller.rb +2 -0
  46. data/test/tmp/config/routes.rb +17 -0
  47. metadata +76 -6
  48. data/test/tmp/config/initializers/knock.rb +0 -86
@@ -1,86 +0,0 @@
1
- Knock.setup do |config|
2
-
3
- ## User handle attribute
4
- ## ---------------------
5
- ##
6
- ## The attribute used to uniquely identify a user.
7
- ##
8
- ## Default:
9
- # config.handle_attr = :email
10
-
11
- ## Current user retrieval from handle when signing in
12
- ## --------------------------------------------------
13
- ##
14
- ## This is where you can configure how to retrieve the current user when
15
- ## signing in.
16
- ##
17
- ## Knock uses the `handle_attr` variable to retrieve the handle from the
18
- ## AuthTokenController parameters. It also uses the same variable to enforce
19
- ## permitted values in the controller.
20
- ##
21
- ## You must raise ActiveRecord::RecordNotFound if the resource cannot be retrieved.
22
- ##
23
- ## Default:
24
- # config.current_user_from_handle = -> (handle) { User.find_by! Knock.handle_attr => handle }
25
-
26
- ## Current user retrieval when validating token
27
- ## --------------------------------------------
28
- ##
29
- ## This is how you can tell Knock how to retrieve the current_user.
30
- ## By default, it assumes you have a model called `User` and that
31
- ## the user_id is stored in the 'sub' claim.
32
- ##
33
- ## You must raise ActiveRecord::RecordNotFound if the resource cannot be retrieved.
34
- ##
35
- ## Default:
36
- # config.current_user_from_token = -> (claims) { User.find claims['sub'] }
37
-
38
-
39
- ## Expiration claim
40
- ## ----------------
41
- ##
42
- ## How long before a token is expired.
43
- ##
44
- ## Default:
45
- # config.token_lifetime = 1.day
46
-
47
-
48
- ## Audience claim
49
- ## --------------
50
- ##
51
- ## Configure the audience claim to identify the recipients that the token
52
- ## is intended for.
53
- ##
54
- ## Default:
55
- # config.token_audience = nil
56
-
57
- ## If using Auth0, uncomment the line below
58
- # config.token_audience = -> { Rails.application.secrets.auth0_client_id }
59
-
60
- ## Signature algorithm
61
- ## -------------------
62
- ##
63
- ## Configure the algorithm used to encode the token
64
- ##
65
- ## Default:
66
- # config.token_signature_algorithm = 'HS256'
67
-
68
- ## Signature key
69
- ## -------------
70
- ##
71
- ## Configure the key used to sign tokens.
72
- ##
73
- ## Default:
74
- # config.token_secret_signature_key = -> { Rails.application.secrets.secret_key_base }
75
-
76
- ## If using Auth0, uncomment the line below
77
- # config.token_secret_signature_key = -> { JWT.base64url_decode Rails.application.secrets.auth0_client_secret }
78
-
79
- ## Public key
80
- ## ----------
81
- ##
82
- ## Configure the public key used to decode tokens, if required.
83
- ##
84
- ## Default:
85
- # config.token_public_key = nil
86
- end