@@ -13,7 +13,10 @@ Before the session_start() use the command:
1313
1414``` php
1515<?php
16- $handler = new \ByJG\Session\JwtSession('your.domain.com', 'your super secret key');
16+ $sessionConfig = (new \ByJG\Session\SessionConfig('your.domain.com'))
17+ ->withSecret('your super secret key');
18+
19+ $handler = new \ByJG\Session\JwtSession($sessionConfig);
1720session_set_save_handler($handler, true);
1821```
1922
@@ -34,7 +37,7 @@ Just to use.
3437You can read more in this Codementor's article:
3538[ Using JSON Web Token (JWT) as a PHP Session] ( https://www.codementor.io/byjg/using-json-web-token-jwt-as-a-php-session-axeuqbg1m )
3639
37- ## Security Information
40+ # Security Information
3841
3942The JWT Token cannot be changed, but it can be read.
4043This implementation save the JWT into a client cookie.
@@ -43,47 +46,119 @@ Because of this _**do not** store in the JWT Token sensible data like passwords_
4346# Install
4447
4548```
46- composer require "byjg/jwt-session=1 .0.*"
49+ composer require "byjg/jwt-session=2 .0.*"
4750```
4851
49- # Customizations
5052
51- ## Setting the validity of JWT Token
53+ # Setting the validity of JWT Token
5254
5355``` php
5456<?php
55- // Setting to 50 minutes
56- $handler = new \ByJG\Session\JwtSession('your.domain.com', 'your super secret key', 50);
57+ $sessionConfig = (new \ByJG\Session\SessionConfig('your.domain.com'))
58+ ->withSecret('your super secret key')
59+ ->withTimeoutMinutes(60); // You can use withTimeoutHours(1)
60+
61+ $handler = new \ByJG\Session\JwtSession($sessionConfig);
5762session_set_save_handler($handler, true);
5863```
5964
60- ## Setting the different Session Contexts
65+ # Setting the different Session Contexts
6166
6267``` php
6368<?php
64- $handler = new \ByJG\Session\JwtSession('your.domain.com', 'your super secret key', 20, 'MYCONTEXT');
69+ $sessionConfig = (new \ByJG\Session\SessionConfig('your.domain.com'))
70+ ->withSecret('your super secret key')
71+ ->withSessionContext('MYCONTEXT');
72+
73+ $handler = new \ByJG\Session\JwtSession($sessionConfig);
6574session_set_save_handler($handler, true);
6675```
6776
68- ## Create the handler and replace the session handler
77+ # Create the handler and replace the session handler
78+
79+ ``` php
80+ <?php
81+ $sessionConfig = (new \ByJG\Session\SessionConfig('your.domain.com'))
82+ ->withSecret('your super secret key')
83+ ->replaceSessionHandler();
84+
85+ $handler = new \ByJG\Session\JwtSession($sessionConfig);
86+ ```
87+
88+ # Specify cookie domain
6989
7090``` php
7191<?php
72- $handler = new \ByJG\Session\JwtSession('your.domain.com', 'your super secret key');
73- $handler->replaceSessionHandler(true);
92+ $sessionConfig = (new \ByJG\Session\SessionConfig('your.domain.com'))
93+ ->withSecret('your super secret key')
94+ ->withCookie('.mydomain.com', '/')
95+ ->replaceSessionHandler();
96+
97+ $handler = new \ByJG\Session\JwtSession($sessionConfig);
7498```
7599
76- ## Create the handler and replace the session handler, specifying cookie domain valid for all subdomains of mydomain.com
100+ # Uses RSA Private/Public Keys
77101
78102``` php
79103<?php
80- $handler = new \ByJG\Session\JwtSession('your.domain.com', 'your super secret key', null, null, '.mydomain.com');
81- $handler->replaceSessionHandler(true);
104+ $secret = <<<PRIVATE
105+ -----BEGIN RSA PRIVATE KEY-----
106+ MIIEpQIBAAKCAQEA5PMdWRa+rUJmg6QMNAPIXa+BJVN7W0vxPN3WTK /OIv5gxgmj
107+ 2inHGGc6f90TW /to948LnqGtcD3CD9KsI55MubafwBYjcds1o9opZ0vYwwdIV80c
108+ OVZX1IUZFTbnyyKcXeFmKt49A52haCiy4iNxcRK38tOCApjZySx /NzMDeaXuWe+1
109+ nd3pbgYa /I8MkECa5EyabhZJPJo9fGoSZIklNnyq4TfAUSwl+KN /zjj3CXad1oDT
110+ 7XDDgMJDUu /Vxs7h3CQI9zILSYcL9zwttbLnJW1WcLlAAIaAfABtSZboznsStMnY
111+ to01wVknXKyERFs7FLHYqKQANIvRhFTptsehowIDAQABAoIBAEkJkaQ5EE0fcKqw
112+ K8BwMHxKn81zi1e9q1C6iEHgl8csFV03+BCB4WTUkaH2udVPJ9ZJyPArLbQvz3fS
113+ wl1+g4V /UAksRtRslPkXgLvWQ2k8KoTwBv /3nn9Kkozk /h8chHuii0BDs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IPaU44+lZzTMHBOJBGMJKi8WogKi
130+ V5+cz9l31uuAgNfjL63jZPaAzKs8Zx6R3O5RuezympwijCIGWILbO2Q =
131+ -----END RSA PRIVATE KEY-----
132+ PRIVATE;
133+
134+ $public = <<<PUBLIC
135+ -----BEGIN PUBLIC KEY-----
136+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5PMdWRa+rUJmg6QMNAPI
137+ Xa+BJVN7W0vxPN3WTK /OIv5gxgmj2inHGGc6f90TW /to948LnqGtcD3CD9KsI55M
138+ ubafwBYjcds1o9opZ0vYwwdIV80cOVZX1IUZFTbnyyKcXeFmKt49A52haCiy4iNx
139+ cRK38tOCApjZySx /NzMDeaXuWe+1nd3pbgYa /I8MkECa5EyabhZJPJo9fGoSZIkl
140+ Nnyq4TfAUSwl+KN /zjj3CXad1oDT7XDDgMJDUu /Vxs7h3CQI9zILSYcL9zwttbLn
141+ JW1WcLlAAIaAfABtSZboznsStMnYto01wVknXKyERFs7FLHYqKQANIvRhFTptseh
142+ owIDAQAB
143+ -----END PUBLIC KEY-----
144+ PUBLIC;
145+
146+ $sessionConfig = (new \ByJG\Session\SessionConfig( ' example.com' ))
147+ - >withRsaSecret($secret, $public)
148+ ->replaceSessionHandler();
149+
150+ $handler = new \ByJG\Session\JwtSession($sessionConfig);
82151```
83152
84- ## How it works
153+ If you want to know more details about how to create RSA Public/Private Keys access:
154+ https://github.com/byjg/jwt-wrapper
155+
156+
157+ # How it works
85158
86159We store a cookie named AUTH_BEARER_ <context name > with the session name. The PHPSESSID cookie is still created because
87160PHP create it by default but we do not use it;
88161
89162
163+ ----
164+ [ Open source ByJG] ( http://opensource.byjg.com )
0 commit comments