SlideShare uma empresa Scribd logo
1 de 138
Baixar para ler offline
deSymfony 30 junio - 1 julio 2017
Castellón
ASEGURANDO APIS
EN SYMFONY CON JWT
Nacho Martín
deSymfony
¡Muchas gracias a nuestros
patrocinadores!
Programo en Limenius
Casi todos los proyectos
necesitan una API
Hacemos aplicaciones a medida
con Symfony y React
JWT es una buena herramienta
para asegurarlas
Por qué es esto necesario
Por qué es esto necesario
¿Por qué no está todo inventado?
Esta charla va de alivios
Esta charla va de alivios
Autenticación con Cookies
Cliente
(navegador)
Servidor
BD
POST /login_check
username: "nacho",
password: "patata"
Autenticación con Cookies
Cliente
(navegador)
Servidor
BD
Obtiene usuario
Verifica credenciales
Guarda sesión
Autenticación con Cookies
Cliente
(navegador)
Servidor
BD
Envía cookie
al cliente
Set-Cookie: PHPSESSIONID=HOLA…
Autenticación con Cookies
Cliente
(navegador)
Servidor
BD
Usa cookie para
identificarse
Cookie: PHPSESSIONID=HOLA
Problemas con Cookies
Problemas con CORS
Implementación no natural en algunos clientes
Hay que protegerse contra CSRF
Requiere una gestión de sesión y pensar en cómo escalar
Mantienen un estado (sesión)
Estado en REST
[…] communication must be stateless in nature, […], such that
each request from client to server must contain all of the
information necessary to understand the request, and
cannot take advantage of any stored context on the
server. Session state is therefore kept entirely on the client.
Cómo siempre, hay razones
Requiere una gestión de sesión, y pensar en cómo escalar
¿Qué hacer con un balanceador de carga?
¿Dónde guardar las sesiones?
Alternativas para APIs
Junio 2012
JSON Web Tokens (JWT)
JOSE
JSON Object Signing and Encryption
{
JWT
JWA
JWS
JWE
JWK
JOSE
JSON Object Signing and Encryption
{
JWT
JWA
JWS
JWE
JWK
JWT solo es un formato de tokens
Pero muchas veces decimos “usar JWT”
Para referirnos a una forma de trabajar con ellos
https://www.flickr.com/photos/tokencompany/8073379662
Autenticación con JWT
Cliente
(navegador)
Servidor
BD
POST /login_check
username: "nacho",
password: "patata"
Autenticación con JWT
Cliente
(navegador)
Servidor
BD
Obtiene usuario
Verifica credenciales
Guarda sesión?
Autenticación con JWT
Cliente
(navegador)
Servidor
BD
Envía token
al cliente
{“token”:"tomaUnToken"}
Autenticación con JWT
Cliente
(navegador)
Servidor
BD
Usa token para
identificarse
Authorization: Bearer tomaUnToken
Uso en JavaScript
fetch(baseUrl + '/admin/api/recipes', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer '+token,
},
body: JSON.stringify( data )
})
Almacenamiento en JavaScript
window.localStorage.setItem('access_token', token)
window.localStorage.getItem('access_token')
Almacenamiento en JavaScript
window.localStorage.setItem('access_token', token)
window.localStorage.getItem('access_token')
Ya no tenemos CSRF, ahora ojo con ataques XSS
El famoso token
eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVIiXSwid
XNlcm5hbWUiOiJuYWNobyIsImlhdCI6MTQ5ODE0MjA3Niw
iZXhwIjoxNDk4MTQ1Njc2fQ
eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVIiXSwid
XNlcm5hbWUiOiJuYWNobyIsImlhdCI6MTQ5ODE0MjA3Niw
iZXhwIjoxNDk4MTQ1Njc2fQ
El famoso token
eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVIiXSwid
XNlcm5hbWUiOiJuYWNobyIsImlhdCI6MTQ5ODE0MjA3Niw
iZXhwIjoxNDk4MTQ1Njc2fQ
Hay un punto
El famoso token
El famoso token
eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVIiXSwid
XNlcm5hbWUiOiJuYWNobyIsImlhdCI6MTQ5ODE0MjA3Niw
iZXhwIjoxNDk4MTQ1Njc2fQ
El famoso token
eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVIiXSwid
XNlcm5hbWUiOiJuYWNobyIsImlhdCI6MTQ5ODE0MjA3Niw
iZXhwIjoxNDk4MTQ1Njc2fQ
{“alg":"none"}
{
“username":"nacho",
“iat":1498142076,
“exp”:1498145676
}
Base64Url
eyJhbGciOiJSUzI1NiJ9{“alg":"none"}
No está cifrado (todos lo pueden leer)
Solo está codificado
Esto solo sirve para que pueda viajar en URLs
Y en cualquier sitio donde puedan viajar strings
Base64Url
{
“username":"nacho",
“iat":1498142076,
“exp”:1498145676
}
¿Me puedo fiar de esto?
Base64Url
{
“username":"nacho",
“iat":1498142076,
“exp”:1498145676
}
¿Me puedo fiar de esto?
El token completo
eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVIiXSwidXNlcm5hbWUiOiJuYWNobyIsImlhdCI6MTQ5ODE0MjA3NiwiZXh
wIjoxNDk4MTQ1Njc2fQ.jomtnO16Tik6jxU_0HmsXFxbUSyBoNTu8RVSbQ9jEKUfYEFTG8QZrsSpNl5uzlXf-
hP2zx1YmPTow1jXGyoFjV6Nk1e7pFlw2s8fSrIZpT2ZFBuVPefKhSWXYoSUHGZWtMFMU-
yghnWA6tlFD5UcJiDQ3ZlUCbLxOlDdygUoC841aR9R87otefdQUEKY_faGq1Tl-
KxJfjndG4HENgC7M52JaX5xFKmOlI1mKXqDvVOrCTil3yOcqxQv94SZjqhG5V7NLaaslMDXVl4fzJC-
WWE_Eo0xzfOSxMAZ7NBEvha207pjl8FAszQDZ0uuqxfPLqb4QnpALnFAGip4hlu28wRccAsWJQ6uSYtClrE9Kwt7Vlo4PrPX3zqMb
_YaRI1QUco6qjj2AsCf18-0f5XvgqrwSoU_73w4pgsj7rUyft9mwe3tiUYCoUP_dKFJfcz_ofHScpsWfFJ4lD4TIzpKf1LfLFwRUcpQuJdR
K8-1C_x5dJILrO2fSKZbxFCq_-
zB2UHmbH8eFQQYxIpS4eDjFDZTeFLOzruapM10taDQ8buGOyVUx9vwTJoWq9dFuqVAdhFc9h6iXNy0QzI46uvN-
en1n6KVsKTfaLecvCYhIIt32Z5mYD3YgDEeRnLZ5TIgykiVNL9SZCGphzv6h5MEs_xQyDo6XOsu92tPtbqyvI4
El token completo
eyJhbGciOiJSUzI1NiJ9.eyJyb2xlcyI6WyJST0xFX1VTRVIiXSwidXNlcm5hbWUiOiJuYWNobyIsImlhdCI6MTQ5ODE0MjA3NiwiZXh
wIjoxNDk4MTQ1Njc2fQ.jomtnO16Tik6jxU_0HmsXFxbUSyBoNTu8RVSbQ9jEKUfYEFTG8QZrsSpNl5uzlXf-
hP2zx1YmPTow1jXGyoFjV6Nk1e7pFlw2s8fSrIZpT2ZFBuVPefKhSWXYoSUHGZWtMFMU-
yghnWA6tlFD5UcJiDQ3ZlUCbLxOlDdygUoC841aR9R87otefdQUEKY_faGq1Tl-
KxJfjndG4HENgC7M52JaX5xFKmOlI1mKXqDvVOrCTil3yOcqxQv94SZjqhG5V7NLaaslMDXVl4fzJC-
WWE_Eo0xzfOSxMAZ7NBEvha207pjl8FAszQDZ0uuqxfPLqb4QnpALnFAGip4hlu28wRccAsWJQ6uSYtClrE9Kwt7Vlo4PrPX3zqMb
_YaRI1QUco6qjj2AsCf18-0f5XvgqrwSoU_73w4pgsj7rUyft9mwe3tiUYCoUP_dKFJfcz_ofHScpsWfFJ4lD4TIzpKf1LfLFwRUcpQuJdR
K8-1C_x5dJILrO2fSKZbxFCq_-
zB2UHmbH8eFQQYxIpS4eDjFDZTeFLOzruapM10taDQ8buGOyVUx9vwTJoWq9dFuqVAdhFc9h6iXNy0QzI46uvN-
en1n6KVsKTfaLecvCYhIIt32Z5mYD3YgDEeRnLZ5TIgykiVNL9SZCGphzv6h5MEs_xQyDo6XOsu92tPtbqyvI4
header.claims.signature
Pero sí está firmado (los intermediarios no lo
pueden modificar sin que nos enteremos)
No está cifrado
Header
{
“typ”:”JWT”,
“alg”:”RS256”
}
Header
{
“typ”:”JWT”,
“alg”:”RS256”
}
Tipo de token
Header
{
“typ”:”JWT”,
“alg”:”RS256”
}
Tipo de token
Algoritmo de hashing
¿Qué algoritmo usar?
JWA (rfc7518)
Diferencia simétrico/asimétrico
Simétrico: usamos la misma clave para firmar y validar.
Asimétrico: usamos distintas claves para firmar y validar.
RS256
RS384
RS512
Algoritmos
HS256
HS384
HS512
ES256
ES384
ES512
HMAC ECDSA RSA
PS256
PS384
PS348
RSASSA-PSS
none
RS256
RS384
RS512
Algoritmos
HS256
HS384
HS512
ES256
ES384
ES512
HMAC ECDSA RSA
PS256
PS384
PS348
RSASSA-PSS
none
Simétrico
RS256
RS384
RS512
Algoritmos
HS256
HS384
HS512
ES256
ES384
ES512
HMAC ECDSA RSA
PS256
PS384
PS348
RSASSA-PSS
none
Simétrico Asimétricos
RS256
RS384
RS512
Algoritmos
HS256
HS384
HS512
ES256
ES384
ES512
HMAC ECDSA
RS256
RS384
RS512
RSA
PS256
PS384
PS348
RSASSA-PSS
none
Simétrico Asimétricos
Claims
{
“username":"nacho",
“iat":1498142076,
“exp”:1498145676
}
Registered claims
jti
iss
aud
sub
iat
exp
nbf
Id del token: String
Issuer (emisor): StringOrUri
Audiencia: StringOrUri
Subject (tema): StringOrUri
Cuándo se creó: NumericDate
Cuándo expira: NumericDate
Tiempo hasta válidez: NumericDate
Custom claims
{
“username":"nacho",
“iat":1498142076,
“exp”:1498145676
}
Podemos añadir lo que queramos.
Solo hay que tener en cuenta:
Ser conciso.
Los datos no van cifrados (el cliente los ve).
Firma
Signature = algoritmo(payload, key)
Payload = Base64URL(headers)
+ ”.”
+ Base64URL(claims)
JWS (rfc7515)
JWT.IO
Importante: Usar TLS (“SSL”)
Ventajas de JWT
Caso: Mi app en JavaScript se ve distinta
dependiendo del rol del usuario
Con Cookies
Cliente Servidor
BD
Cookie: PHPSESSIONID=HOLA
Con Cookies
Cliente Servidor
BD
Cookie: PHPSESSIONID=HOLA
Tengo una cookie pero
no sé qué usuario soy
ni qué permisos tengo
Con Cookies
Cliente Servidor
BD
Cookie: PHPSESSIONID=HOLA
Con Cookies
Cliente Servidor
BD
Cookie: PHPSESSIONID=HOLA
Obtener usuario
Con Cookies
Cliente Servidor
BD
Cookie: PHPSESSIONID=HOLA
Obtener usuario
Con Cookies
Cliente Servidor
BD
Cookie: PHPSESSIONID=HOLA
Obtener usuario
Con Cookies
Cliente Servidor
BD
Cookie: PHPSESSIONID=HOLA
Obtener usuario
Con Cookies
Cliente Servidor
BD
Cookie: PHPSESSIONID=HOLA
Obtener usuario
Y ahora mostramos
Con JWT
Cliente Servidor
BD
Token: ejh9…
Con JWT
Cliente Servidor
BD
Token: ejh9…
{
“username":"nacho",
“iat":1498142076,
“exp”:1498145676
}
Con JWT
Cliente Servidor
BD
Token: ejh9…
{
“username":"nacho",
“iat":1498142076,
“exp”:1498145676
}
Tenemos todos los datos
Con JWT
Cliente
Token: ejh9…
{
“username":"nacho",
“iat":1498142076,
“exp”:1498145676
}
Tenemos todos los datos
Microservicios
Auth
Clave privada y pública
Consulta
Clave pública
Cliente
Clave pública
Pedidos
Clave pública
Microservicios
Auth
Clave privada y pública
Consulta
Clave pública
Cliente
Clave pública
Pedidos
Clave pública
{
“aud”:”consulta",
}
Microservicios
Auth
Clave privada y pública
Consulta
Clave pública
Cliente
Clave pública
Pedidos
Clave pública
{
“aud”:”consulta",
}
✘
Microservicios
Auth
Clave privada
Consulta
Cliente
Clave pública
Clave pública
Pedidos
Gateway
Soporte en PHP
lcobucci/jwt
Crear tokens
use LcobucciJWTBuilder;
use LcobucciJWTSignerKeychain;
use LcobucciJWTSignerRsaSha256;
$signer = new Sha256();
$keychain = new Keychain();
$privateKey = $keychain->getPrivateKey('file://path');
$token = (new Builder())->setIssuer('http://example.com')
->setAudience('http://example.org')
->setId('4f1g23a12aa', true)
->setIssuedAt(time())
->setNotBefore(time() + 60)
->setExpiration(time() + 3600)
->set('uid', 1)
->sign($signer, $privateKey)
->getToken();
Validar tokens
use LcobucciJWTSignerKeychain;
use LcobucciJWTSignerRsaSha256;
use LcobucciJWTValidationData;
$signer = new Sha256();
$keychain = new Keychain();
$publicKey = $keychain->getPublicKey('file://path');
$data = newValidationData();
$data->setIssuer('http://example.com');
$data->setAudience('http://example.org');
$data->setId('4f1g23a12aa');
$token->validate($data);
$token->verify($signer, $publicKey);
LexikJWTAuthenticationBundle
Instalación
composer require lexik/jwt-authentication-bundle
$bundles = array(
// ...
new LexikBundleJWTAuthenticationBundleLexikJWTAuthenticationBundle(),
// ...
);
app/config/AppKernel.php
Crear claves
$ openssl genrsa -out var/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in app/jwt/private.pem -out var/jwt/public.pem
Crear claves
$ openssl genrsa -out var/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in app/jwt/private.pem -out var/jwt/public.pem
Clave privada
Crear claves
$ openssl genrsa -out var/jwt/private.pem -aes256 4096
$ openssl rsa -pubout -in app/jwt/private.pem -out var/jwt/public.pem
Clave privada
Clave pública
Configuración
app/config/parameters.yml
app/config/config.yml
lexik_jwt_authentication:
private_key_path: %jwt_private_key_path%
public_key_path: %jwt_public_key_path%
pass_phrase: %jwt_key_pass_phrase%
token_ttl: %jwt_token_ttl%
parameters:
jwt_private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
jwt_public_key_path: '%kernel.root_dir%/../var/jwt/public.pem'
jwt_key_pass_phrase: patata
jwt_token_ttl: 3600
Configuración
app/config/parameters.yml
app/config/config.yml
lexik_jwt_authentication:
private_key_path: %jwt_private_key_path%
public_key_path: %jwt_public_key_path%
pass_phrase: %jwt_key_pass_phrase%
token_ttl: %jwt_token_ttl%
encoder:
service: lexik_jwt_authentication.encoder.lcobucci
parameters:
jwt_private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
jwt_public_key_path: '%kernel.root_dir%/../var/jwt/public.pem'
jwt_key_pass_phrase: patata
jwt_token_ttl: 3600
Configuración
app/config/parameters.yml
app/config/config.yml
lexik_jwt_authentication:
private_key_path: %jwt_private_key_path%
public_key_path: %jwt_public_key_path%
pass_phrase: %jwt_key_pass_phrase%
token_ttl: %jwt_token_ttl%
encoder:
service: lexik_jwt_authentication.encoder.lcobucci
parameters:
jwt_private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
jwt_public_key_path: '%kernel.root_dir%/../var/jwt/public.pem'
jwt_key_pass_phrase: patata
jwt_token_ttl: 3600
Probablemente será default en algún punto
firewalls:
login:
pattern: ^/api/login
stateless: true
anonymous: true
form_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
api:
pattern: ^/api
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
Security config
app/config/security.yml
firewalls:
login:
pattern: ^/api/login
stateless: true
anonymous: true
form_login:
check_path: /api/login_check
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
api:
pattern: ^/api
stateless: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
Security config
app/config/security.yml
No asigna cookies
Routing config
app/config/routing.yml
api_login_check:
path: /api/login_check
Extender el bundle
Eventos
JWT_CREATED: Añadir/quitar datos a claims.
JWT_DECODED: Validaciones extra.
JWT_AUTHENTICATED: Añadir datos al token de Symfony.
AUTHENTICATION_FAILURE
JWT_INVALID
JWT_NOT_FOUND
JWT_EXPIRED
}Cambiar respuestas.
AUTHENTICATION_SUCCESS
Añadir/quitar datos a payload
class JWTCreatedListener
{
public function onJWTCreated(JWTCreatedEvent $event)
{
$payload = $event->getData();
$user = $event->getUser();
if ($user->canOrder()) {
$payload['aud'] = ‘pedidos';
}
$event->setData($payload);
}
}
Comprobaciones extra
class JWTDecodedListener
{
public function onJWTDecoded(JWTDecodedEvent $event)
{
$payload = $event->getPayload();
if (!isset($payload['aud'])
|| $payload['aud'] !== 'pedidos') {
$event->markAsInvalid();
}
}
}
Añadir atributo API a Token Sf
class JWTAuthenticatedListener
{
public function onJWTAuthenticated(JWTAuthenticatedEvent $event)
{
$token = $event->getToken();
$token->setAttribute('api', true);
}
}
public function pagesAction(Request $request)
{
if ($this->get(‘security.token_storage')
->getToken()
->getAttribute(‘api')) {
return new JsonResponse('hola usuario de api');
}
}
¿Qué pasa si quiero…?
Tener diferentes estrategias en distintos firewalls
Hacer algo muy particular
Security
AuthenticationProviderInterface
Security
AuthenticationProviderInterface
UserProvider
Security
AuthenticationEntryPointInterface
AuthenticationProviderInterface
UserProvider
Security
AuthenticationListener
AuthenticationEntryPointInterface
AuthenticationProviderInterface
UserProvider
Security
AuthenticationListener
AuthenticationEntryPointInterface
AuthenticationProviderInterface
UserProvider
Security
Events
AuthenticationListener
AuthenticationEntryPointInterface
AuthenticationProviderInterface
UserProvider
Security
Events
UserInterface
AuthenticationListener
AuthenticationEntryPointInterface
AuthenticationProviderInterface
AbstractToken
UserProvider
Security
Events
UserInterface
AuthenticationListener
AuthenticationEntryPointInterface
AuthenticationProviderInterface
AbstractToken
UserProvider
Security
Voters
Events
UserInterface
UserProvider
UserProvider
👌
AuthenticationListener
AuthenticationEntryPointInterface
AuthenticationProviderInterface
AbstractToken
UserProvider
Security
Voters
Events
UserInterface
Guard 💂
👌
La interfaz GuardAuthenticator
interface GuardAuthenticatorInterface
{
public function getCredentials(Request $request);
public function getUser($credentials, UserProviderInterface $userProvider);
public function checkCredentials($credentials, UserInterface $user);
public function createAuthenticatedToken(UserInterface $user, $providerKey);
public function onAuthenticationFailure(Request $request,AuthenticationException $exception);
public function onAuthenticationSuccess(Request $request,TokenInterface $token, $providerKey);
public function supportsRememberMe();
}
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe
Validar token
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe
Validar token
Obtener usuario a partir de JWT
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe
Validar token
Obtener usuario a partir de JWT
true
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe
Validar token
Obtener usuario a partir de JWT
true
Crear token de Symfony (no JWT)
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe
Devolver respuesta adecuada
Validar token
Obtener usuario a partir de JWT
true
Crear token de Symfony (no JWT)
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe
No hacer nada
Devolver respuesta adecuada
Validar token
Obtener usuario a partir de JWT
true
Crear token de Symfony (no JWT)
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe false
No hacer nada
Devolver respuesta adecuada
Validar token
Obtener usuario a partir de JWT
true
Crear token de Symfony (no JWT)
La interfaz GuardAuthenticator
getCredentials
getUser
checkCredentials
createAuthenticatedToken
onAuthenticationFailure
onAuthenticationSuccess
supportsRememberMe false
No hacer nada
Devolver respuesta adecuada
Validar token
Obtener usuario a partir de JWT
true
Crear token de Symfony (no JWT)
JWTTokenAuthenticator
use LexikBundleJWTAuthenticationBundleSecurityGuardJWTTokenAuthenticator as BaseAuthenticator;
class MiTokenAuthenticator extends BaseAuthenticator
{
}
security:
# ...
firewalls:
# ...
otra_api:
pattern: ^/otraapi
stateless: true
guard:
authenticators:
- app.mi_token_authenticator
FAQ
Oauth vs JWT? Oauth + JWT?
Usos fuera de headers
token_extractors:
authorization_header:
enabled: true
prefix: Bearer
name: Authorization
cookie:
enabled: false
name: BEARER
query_parameter:
enabled: false
name: bearer
Cuántos datos caben en un token?
https://www.flickr.com/photos/highwaysagency/6008275527
Invalidar tokens
Enlaces con caducidad
$user = $this->getUser();
$jwtManager = $this->get('lexik_jwt_authentication.jwt_manager');
$token2 = $jwtManager->create($user);
<a href="{{ path('reset_password', {'bearer':authToken.credentials}) }}”>
Reset password
</a>
Controlador
Vista
Renovar tokens
👌
Impersonar usuarios en APIs
👌
Impersonar usuarios en APIs
HEADER:
X-Switch-User: johndoe
Requests a otros dominios
👌
Ejemplo de uso con React
¡Gracias!
@nacmartin
nacho@limenius.com
http://limenius.com
Formación, consultoría
y desarrollo de proyectos

Mais conteúdo relacionado

Mais procurados

Estructuras de control en PHP
Estructuras de control en PHPEstructuras de control en PHP
Estructuras de control en PHPupresentaciones
 
Workshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationWorkshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationAntoine Rey
 
How to develop automated tests
How to develop automated testsHow to develop automated tests
How to develop automated testsOdoo
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servletsvishal choudhary
 
Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Anton Arhipov
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deploymentsOdoo
 
Fases de diseño del modelo de simulación.
Fases de diseño del modelo de simulación.Fases de diseño del modelo de simulación.
Fases de diseño del modelo de simulación.Roberto Dominguez
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern Nirthika Rajendran
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON APIpodsframework
 
Investigacion Operativa II.pdf
Investigacion Operativa II.pdfInvestigacion Operativa II.pdf
Investigacion Operativa II.pdfPEREZRIVASYESSICA
 
Administracion de operaciones_-_completo-300-330
Administracion de operaciones_-_completo-300-330Administracion de operaciones_-_completo-300-330
Administracion de operaciones_-_completo-300-330Edi Chacon
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredDanish Mehraj
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android Aakash Ugale
 
Dynamic HTML Event Model
Dynamic HTML Event ModelDynamic HTML Event Model
Dynamic HTML Event ModelReem Alattas
 
유니티 REST API를 사용한 파이어 베이스의 데이터 베이스 사용.
유니티 REST API를 사용한 파이어 베이스의 데이터 베이스 사용.유니티 REST API를 사용한 파이어 베이스의 데이터 베이스 사용.
유니티 REST API를 사용한 파이어 베이스의 데이터 베이스 사용.ssuser6dd171
 

Mais procurados (20)

Curso Java Avanzado 5 Ejb
Curso Java Avanzado   5 EjbCurso Java Avanzado   5 Ejb
Curso Java Avanzado 5 Ejb
 
Estructuras de control en PHP
Estructuras de control en PHPEstructuras de control en PHP
Estructuras de control en PHP
 
Workshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationWorkshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring Integration
 
How to develop automated tests
How to develop automated testsHow to develop automated tests
How to develop automated tests
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
 
Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012
 
Js: master prototypes
Js: master prototypesJs: master prototypes
Js: master prototypes
 
PROMODEL EJERCICIO DE PROCESO
PROMODEL EJERCICIO DE PROCESO PROMODEL EJERCICIO DE PROCESO
PROMODEL EJERCICIO DE PROCESO
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
 
Fases de diseño del modelo de simulación.
Fases de diseño del modelo de simulación.Fases de diseño del modelo de simulación.
Fases de diseño del modelo de simulación.
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON API
 
Investigacion Operativa II.pdf
Investigacion Operativa II.pdfInvestigacion Operativa II.pdf
Investigacion Operativa II.pdf
 
Administracion de operaciones_-_completo-300-330
Administracion de operaciones_-_completo-300-330Administracion de operaciones_-_completo-300-330
Administracion de operaciones_-_completo-300-330
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Dynamic HTML Event Model
Dynamic HTML Event ModelDynamic HTML Event Model
Dynamic HTML Event Model
 
유니티 REST API를 사용한 파이어 베이스의 데이터 베이스 사용.
유니티 REST API를 사용한 파이어 베이스의 데이터 베이스 사용.유니티 REST API를 사용한 파이어 베이스의 데이터 베이스 사용.
유니티 REST API를 사용한 파이어 베이스의 데이터 베이스 사용.
 
Metodos numericos act_3
Metodos numericos act_3Metodos numericos act_3
Metodos numericos act_3
 
Flask
FlaskFlask
Flask
 

Semelhante a Asegurando APIs en Symfony con JWT

Autenticar y securizar API en .NET Core como un Avenger
Autenticar y securizar API en .NET Core como un AvengerAutenticar y securizar API en .NET Core como un Avenger
Autenticar y securizar API en .NET Core como un AvengerAdrian Diaz Cervera
 
Meetup En mi local funciona - Protegiendo tu API REST con JWT en aplicaciones...
Meetup En mi local funciona - Protegiendo tu API REST con JWT en aplicaciones...Meetup En mi local funciona - Protegiendo tu API REST con JWT en aplicaciones...
Meetup En mi local funciona - Protegiendo tu API REST con JWT en aplicaciones...atSistemas
 
MercadoPago
MercadoPagoMercadoPago
MercadoPagofsolari
 
Seguridad para aplicaciones web java con json web tokens (jwt) 2020
Seguridad para aplicaciones web java con json web tokens (jwt)  2020Seguridad para aplicaciones web java con json web tokens (jwt)  2020
Seguridad para aplicaciones web java con json web tokens (jwt) 2020Eudris Cabrera
 
[SOS 2009] Smart Access: Tu DNIe en tu AD
[SOS 2009] Smart Access: Tu DNIe en tu AD[SOS 2009] Smart Access: Tu DNIe en tu AD
[SOS 2009] Smart Access: Tu DNIe en tu ADChema Alonso
 
Hack like a pro with custom VPS - Najava Negra 2019
Hack like a pro with custom VPS - Najava Negra 2019Hack like a pro with custom VPS - Najava Negra 2019
Hack like a pro with custom VPS - Najava Negra 2019Alejandro Quesada
 
Pagos electrónicos
Pagos electrónicosPagos electrónicos
Pagos electrónicosRené Olivo
 
Seguridad en las apis desde un punto de vista de developer
Seguridad en las apis desde un punto de vista de developerSeguridad en las apis desde un punto de vista de developer
Seguridad en las apis desde un punto de vista de developerCloudAppi
 
Qué es eso de OAuth y como se implementa en Symfony2 (y otros)
Qué es eso de OAuth y como se implementa en Symfony2 (y otros)Qué es eso de OAuth y como se implementa en Symfony2 (y otros)
Qué es eso de OAuth y como se implementa en Symfony2 (y otros)Miguel Ángel Sánchez Chordi
 
Comenzando con los servicios móviles en AWS
Comenzando con los servicios móviles en AWSComenzando con los servicios móviles en AWS
Comenzando con los servicios móviles en AWSAmazon Web Services LATAM
 
Seguridad en Aplicaciones Web y Comercio Electrónico
Seguridad en Aplicaciones Web y Comercio ElectrónicoSeguridad en Aplicaciones Web y Comercio Electrónico
Seguridad en Aplicaciones Web y Comercio ElectrónicoRené Olivo
 
3. certificados y pki
3. certificados y pki3. certificados y pki
3. certificados y pki1 2d
 
"Los Imprescindibles de .NetCore"
"Los Imprescindibles de .NetCore""Los Imprescindibles de .NetCore"
"Los Imprescindibles de .NetCore"www.encamina.com
 
Manual Certificado Digital DNIe
Manual Certificado Digital DNIeManual Certificado Digital DNIe
Manual Certificado Digital DNIeSafe Creative
 
Seguridad sql server
Seguridad sql serverSeguridad sql server
Seguridad sql serverEfra Paredes
 

Semelhante a Asegurando APIs en Symfony con JWT (20)

Autenticar y securizar API en .NET Core como un Avenger
Autenticar y securizar API en .NET Core como un AvengerAutenticar y securizar API en .NET Core como un Avenger
Autenticar y securizar API en .NET Core como un Avenger
 
Meetup En mi local funciona - Protegiendo tu API REST con JWT en aplicaciones...
Meetup En mi local funciona - Protegiendo tu API REST con JWT en aplicaciones...Meetup En mi local funciona - Protegiendo tu API REST con JWT en aplicaciones...
Meetup En mi local funciona - Protegiendo tu API REST con JWT en aplicaciones...
 
MercadoPago
MercadoPagoMercadoPago
MercadoPago
 
Seguridad para aplicaciones web java con json web tokens (jwt) 2020
Seguridad para aplicaciones web java con json web tokens (jwt)  2020Seguridad para aplicaciones web java con json web tokens (jwt)  2020
Seguridad para aplicaciones web java con json web tokens (jwt) 2020
 
[SOS 2009] Smart Access: Tu DNIe en tu AD
[SOS 2009] Smart Access: Tu DNIe en tu AD[SOS 2009] Smart Access: Tu DNIe en tu AD
[SOS 2009] Smart Access: Tu DNIe en tu AD
 
Hack like a pro with custom VPS - Najava Negra 2019
Hack like a pro with custom VPS - Najava Negra 2019Hack like a pro with custom VPS - Najava Negra 2019
Hack like a pro with custom VPS - Najava Negra 2019
 
Seguridad en la web
Seguridad en la webSeguridad en la web
Seguridad en la web
 
Construyendo APIs Seguras y Escalables
Construyendo APIs Seguras y Escalables Construyendo APIs Seguras y Escalables
Construyendo APIs Seguras y Escalables
 
Pagos electrónicos
Pagos electrónicosPagos electrónicos
Pagos electrónicos
 
Seguridad en las apis desde un punto de vista de developer
Seguridad en las apis desde un punto de vista de developerSeguridad en las apis desde un punto de vista de developer
Seguridad en las apis desde un punto de vista de developer
 
Qué es eso de OAuth y como se implementa en Symfony2 (y otros)
Qué es eso de OAuth y como se implementa en Symfony2 (y otros)Qué es eso de OAuth y como se implementa en Symfony2 (y otros)
Qué es eso de OAuth y como se implementa en Symfony2 (y otros)
 
Comenzando con los servicios móviles en AWS
Comenzando con los servicios móviles en AWSComenzando con los servicios móviles en AWS
Comenzando con los servicios móviles en AWS
 
Robo desesionesfinal
Robo desesionesfinalRobo desesionesfinal
Robo desesionesfinal
 
Seguridad WEB - Principios básicos.
Seguridad WEB - Principios básicos.Seguridad WEB - Principios básicos.
Seguridad WEB - Principios básicos.
 
Seguridad en Aplicaciones Web y Comercio Electrónico
Seguridad en Aplicaciones Web y Comercio ElectrónicoSeguridad en Aplicaciones Web y Comercio Electrónico
Seguridad en Aplicaciones Web y Comercio Electrónico
 
3. certificados y pki
3. certificados y pki3. certificados y pki
3. certificados y pki
 
"Los Imprescindibles de .NetCore"
"Los Imprescindibles de .NetCore""Los Imprescindibles de .NetCore"
"Los Imprescindibles de .NetCore"
 
Manual Certificado Digital DNIe
Manual Certificado Digital DNIeManual Certificado Digital DNIe
Manual Certificado Digital DNIe
 
Dev conf 2013
Dev conf 2013Dev conf 2013
Dev conf 2013
 
Seguridad sql server
Seguridad sql serverSeguridad sql server
Seguridad sql server
 

Mais de Ignacio Martín

Elixir/OTP for PHP developers
Elixir/OTP for PHP developersElixir/OTP for PHP developers
Elixir/OTP for PHP developersIgnacio Martín
 
Introduction to React Native Workshop
Introduction to React Native WorkshopIntroduction to React Native Workshop
Introduction to React Native WorkshopIgnacio Martín
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and SymfonyIgnacio Martín
 
Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusIgnacio Martín
 
Server Side Rendering of JavaScript in PHP
Server Side Rendering of JavaScript in PHPServer Side Rendering of JavaScript in PHP
Server Side Rendering of JavaScript in PHPIgnacio Martín
 
Extending Redux in the Server Side
Extending Redux in the Server SideExtending Redux in the Server Side
Extending Redux in the Server SideIgnacio Martín
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React AlicanteIgnacio Martín
 
React Native Workshop - React Alicante
React Native Workshop - React AlicanteReact Native Workshop - React Alicante
React Native Workshop - React AlicanteIgnacio Martín
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Ignacio Martín
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projectsIgnacio Martín
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackIgnacio Martín
 
Integrando React.js en aplicaciones Symfony (deSymfony 2016)
Integrando React.js en aplicaciones Symfony (deSymfony 2016)Integrando React.js en aplicaciones Symfony (deSymfony 2016)
Integrando React.js en aplicaciones Symfony (deSymfony 2016)Ignacio Martín
 
Adding Realtime to your Projects
Adding Realtime to your ProjectsAdding Realtime to your Projects
Adding Realtime to your ProjectsIgnacio Martín
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsIgnacio Martín
 

Mais de Ignacio Martín (18)

Elixir/OTP for PHP developers
Elixir/OTP for PHP developersElixir/OTP for PHP developers
Elixir/OTP for PHP developers
 
Introduction to React Native Workshop
Introduction to React Native WorkshopIntroduction to React Native Workshop
Introduction to React Native Workshop
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
 
Symfony 4 Workshop - Limenius
Symfony 4 Workshop - LimeniusSymfony 4 Workshop - Limenius
Symfony 4 Workshop - Limenius
 
Server Side Rendering of JavaScript in PHP
Server Side Rendering of JavaScript in PHPServer Side Rendering of JavaScript in PHP
Server Side Rendering of JavaScript in PHP
 
Extending Redux in the Server Side
Extending Redux in the Server SideExtending Redux in the Server Side
Extending Redux in the Server Side
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 
React Native Workshop - React Alicante
React Native Workshop - React AlicanteReact Native Workshop - React Alicante
React Native Workshop - React Alicante
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6
 
Integrating React.js with PHP projects
Integrating React.js with PHP projectsIntegrating React.js with PHP projects
Integrating React.js with PHP projects
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
 
Integrando React.js en aplicaciones Symfony (deSymfony 2016)
Integrando React.js en aplicaciones Symfony (deSymfony 2016)Integrando React.js en aplicaciones Symfony (deSymfony 2016)
Integrando React.js en aplicaciones Symfony (deSymfony 2016)
 
Adding Realtime to your Projects
Adding Realtime to your ProjectsAdding Realtime to your Projects
Adding Realtime to your Projects
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
 
Symfony 2 CMF
Symfony 2 CMFSymfony 2 CMF
Symfony 2 CMF
 
Doctrine2 sf2Vigo
Doctrine2 sf2VigoDoctrine2 sf2Vigo
Doctrine2 sf2Vigo
 
Presentacion git
Presentacion gitPresentacion git
Presentacion git
 

Asegurando APIs en Symfony con JWT