生成token使用secret
This commit is contained in:
parent
2594ef6dd1
commit
3f23a66f62
@ -28,7 +28,7 @@ fn generate(claim: Claim) -> String {
|
||||
let token = jsonwebtoken::encode(
|
||||
&jsonwebtoken::Header::default(),
|
||||
&claim,
|
||||
&jsonwebtoken::EncodingKey::from_secret(b"secret"),
|
||||
&jsonwebtoken::EncodingKey::from_secret(config!().jwt.secret.as_bytes()),
|
||||
);
|
||||
token.unwrap_or_else(|e| {
|
||||
tracing::error!(error =?e, "生成Token失败");
|
||||
@ -39,7 +39,7 @@ fn generate(claim: Claim) -> String {
|
||||
pub fn verify_token(token: &str) -> Result<Claim, jsonwebtoken::errors::Error> {
|
||||
jsonwebtoken::decode::<Claim>(
|
||||
token,
|
||||
&jsonwebtoken::DecodingKey::from_secret(b"secret"),
|
||||
&jsonwebtoken::DecodingKey::from_secret(config!().jwt.secret.as_bytes()),
|
||||
&jsonwebtoken::Validation::default(),
|
||||
)
|
||||
.map(|data| data.claims)
|
||||
|
Loading…
Reference in New Issue
Block a user