djuro95

Authorization JWT token

Apr 5th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. https://www.youtube.com/watch?v=9YmPI-RUp1c
  2.  
  3.  
  4. lexik/LexikJWTAuthenticationBundle
  5.  
  6. install
  7. composer require "lexik/jwt-authentication-bundle"
  8.  
  9. Register the bundle in app/AppKernel.php
  10.  
  11. ---------------------
  12. public function registerBundles()
  13. {
  14. return array(
  15. //...
  16. new Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBUndle(), //za symfony 3
  17. );
  18. }
  19.  
  20. ---------------------------
  21.  
  22. Generate the SSH keys
  23.  
  24. ---------------------------
  25. config.yml
  26.  
  27. lexik_jwt_authentication:
  28. private_key_path: '%jwt_private_key_path%' - '%kernel.root_dir%/../var/jwt/private.pem
  29. public_key_path: '%jwt_public_key_path%' - '%kernel.root_dir%/../var/jwt/public.pem
  30. pass_phrase: '%jwt_key_pass_phrase%' -jwt_key_pass_phrase ubacujemo u parameters
  31. token_ttl: '%jwt_token_ttl%' = 3600
  32.  
  33. -------------------------
  34. security.yml
  35.  
  36. security:
  37. #...
  38. firewalls:
  39.  
  40. login:
  41. pattern: ^/api/login
  42. stateless: true
  43. anonymous: true
  44. form_login:
  45. check_login: /api/login_check
  46. username_parameter: username
  47. password_parameter: password
  48. success_handler: lexik_jwt_authentication.handler.authentication_success
  49. failure_handler: lexik_jwt_authentication.handler.authentication_failure
  50.  
  51. api:
  52. pattern: ^/api
  53. stateless: true
  54. provider: fos_userbundle
  55. guard:
  56. authenticators:
  57. - lexik_jwt_authentication.jwt_token_authenticator
  58.  
  59. access_control:
  60. - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  61. - { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
  62.  
  63. ---------------------------------------
  64. routing.yml
  65.  
  66. api_login_check:
  67. path: /api/login_check
  68.  
  69.  
  70. ----------------------------------
  71.  
  72. http://localhost:800/api/login_check
  73.  
  74. in postman x-www-form-urlencoded
  75.  
  76. username -> aaaa
  77. password -> aaaa
  78.  
  79.  
  80. -----------------------------
  81.  
  82. for get in postman
  83.  
  84. Headers
  85. *Authorization -> Bearer token - token bez navodnika
Add Comment
Please, Sign In to add comment