- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我尝试对我的 symfony/mongodb 项目实现 LexikJWT 身份验证,我成功地通过静态用户 (in_memory) 进行了身份验证,但我不知道如何使用我自己的用户类来利用它,这是我的代码行:
安全.yml
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
#
# role_hierarchy:
# ROLE_USER: ROLE_USER
# ROLE_CLIENT: ROLE_CLIENT
# ROLE_ADMIN: ROLE_ADMIN
providers:
in_memory:
memory:
users:
wajdi:
password: wajdi
roles: 'ROLE_USER'
aymen:
password: aymen
roles: 'ROLE_ADMIN'
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
anonymous: true
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY }
运行如下命令行即可成功获取token:
curl -X POST http://192.168.1.13:8000/api/login_check -d _username=wajdi -d _password=wajdi
现在我想将我的用户文档设置为提供者,所以我更新成这样:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
providers:
jwt:
lexik_jwt:
class: ApiBundle\Security\User
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
anonymous: true
provider: jwt
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_ANONYMOUSLY }
这就是我的用户文档:
<?php
namespace ApiBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
* @MongoDB\InheritanceType("COLLECTION_PER_CLASS")
*/
class User
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\Field(type="string")
*/
protected $username;
/**
* @MongoDB\Field(type="string")
*/
protected $email;
/**
* @MongoDB\Field(type="string")
*/
protected $password;
/**
* Get id
*
* @return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
* @return self
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string $username
*/
public function getUsername()
{
return $this->username;
}
/**
* Set email
*
* @param string $email
* @return self
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string $email
*/
public function getEmail()
{
return $this->email;
}
/**
* Set password
*
* @param string $password
* @return self
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string $password
*/
public function getPassword()
{
return $this->password;
}
}
我添加了 JWTUserInterface,我正在关注该链接 https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/8-jwt-user-provider.md
但不清楚,没有示例,我需要了解更多详细信息,换句话说,如何将我的用户设置为提供者(通过用户名或电子邮件/密码连接)。
关键字
谢谢。
最佳答案
使用此链接。 https://github.com/m0uj/symfony4-mongodb-jwt-starter这真的很有帮助。检查 security.yaml 文件配置和用户文档如果可能的话,使用 mongodb 提供程序,如下所示:我们的数据库提供者: 数据库: 类别:App\Document\ERPUserMaster 属性:用户名
关于mongodb - 如何为 Lexik JWT 身份验证实现自定义用户提供程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46562846/
1. JWT 简介 JSON Web Token(JWT) 是一个开放标准(RFC 7519),它定义了一种紧凑的、自包含的方式,用于作为 JSON 对象在各方之间安全地传输信息。该信息可以被验证和信
关于JWT(json web token)的一些问题: 可以在手机上使用吗? 在我看来,它适用于移动设备,但它是否是一个很好的身份验证解决方案?如果不是,还有哪些其他解决方案可用于移动应用程序和服务器
我无法清楚地掌握 JWT 是如何工作的,尤其是。签名部分。 一旦客户端提交正确的用户名和密码,身份验证服务器就会创建一个 JWT token ,其中包含 header 、有效负载/声明和签名。 问题
我正在通过 jwt.io(在调试器部分)解码 JWT token 以查看标题、有效负载。令人惊讶的是,它还验证了,我可以看到它(jwt.io 调试器)也能够检索公钥。 所以我的问题是:JWT toke
我尝试使用 validate-jwt 策略限制使用 JWT token 对 REST API 的访问。以前从来没有这样做过。 这是我的入站策略(取自简单 token 验证here):
我们有一个微服务架构,使用 JWT 在服务之间进行身份验证。我希望轻松地从 JWT 中获取更多字段。目前实际上只有权限由 Spring Security 直接公开。 我们的边缘服务/API 网关创建以
我正在尝试在 .NET 中生成 JWT token 。起初,我尝试使用“System.IdentityModel.Tokens.Jwt”,但它在 token 验证期间引起了问题,所以我切换到“jose
我已经阅读了很多关于 stackOverflow 和 jwt 文档的问题。据我了解,现在我应该如何计算 token : header = { "alg": "HS256", "typ": "J
我想知道我可以设置的 JWT token 到期的最大值是多少。 谢谢! 最佳答案 没有关于过期时间的规定。它主要取决于使用 token 的上下文。 RFC7519 section 4 : The se
我在子域上托管了单独的身份验证应用程序和多个 spa 应用程序,我想将生成的 JWT token (当用户从身份验证应用程序登录时生成)从身份验证应用程序共享到子域下托管的其他应用程序。我怎样才能
据我所知,验证 JWT 签名是一个直接的过程。但是当我使用一些在线工具为我执行此操作时,它不匹配。如何在不使用 JWT 库的情况下手动验证 JWT 签名?我需要一种快速方法(使用可用的在线工具)来演示
我的 JSON 网络 token (JWT): eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InU0T2ZORlBId0VCb3NIanRyYXVPYlY4
我是 JWT 的新手。我对 JWT 进行了一些研究,并了解到它的框架是“header.claims.signature”。 考虑一个简单的场景,如下所示: 客户通过身份验证 客户可能具有(一个或多个)
我需要知道的最大长度 JSON Web Token (JWT) 在规范中没有相关信息。难道,长度没有限制? 最佳答案 我也一直在努力寻找这个。 我想说 - 尝试确保它低于 7kb。 虽然 JWT 在规
我看到 JWT token 由 A-Z、a-Z、0-9 和特殊字符 - 和 _ 组成。我想知道 JWT token 中允许的字符列表? 最佳答案 来自JWT introduction :“输出是三个用
我正在使用 Jhipster 创建一个应用程序。为此,我想使用 Keycloak 身份验证服务器。但是,一旦我登录,就会收到以下消息:Statut : Internal Server Error (内
我正在使用 Jhipster 创建一个应用程序。为此,我想使用 Keycloak 身份验证服务器。但是,一旦我登录,就会收到以下消息:Statut : Internal Server Error (内
我在我的网站上使用 MEAN 堆栈,用户可以在其中将带有玩家信息的事件(2-4/事件)添加到购物车。有时他们会购买多个事件。我希望此信息不会受到用户操纵(如果他们使用控制台,则在结帐前更改信息),并且
一个 JSON Web token (JWT) 被分成三个 Base-64 编码的部分,这些部分由句点 (“.”) 连接起来。前两部分对 JSON 对象进行编码,第一部分是详细说明签名和散列算法的 h
我正在使用 django rest 框架 JWT 库 http://getblimp.github.io/django-rest-framework-jwt/ JWT token 过期有两个设置 JW
我是一名优秀的程序员,十分优秀!