mirror of
https://codeberg.org/icewind/rss-webhook-trigger.git
synced 2026-11-30 04:00:49 +01:00
JWT: set kid
This commit is contained in:
parent
7821076b15
commit
2fef24c3f4
1 changed files with 8 additions and 2 deletions
10
src/jwt.rs
10
src/jwt.rs
|
|
@ -9,7 +9,7 @@ use std::{
|
|||
use axum::{Json, Router, extract::State, response::IntoResponse, routing::get, serve};
|
||||
use jsonwebtoken::{
|
||||
Algorithm, Header, encode,
|
||||
jwk::{Jwk, JwkSet, PublicKeyUse},
|
||||
jwk::{Jwk, JwkSet, PublicKeyUse, ThumbprintHash},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::net::{TcpListener, UnixListener};
|
||||
|
|
@ -51,14 +51,20 @@ pub fn generate_token(config: &Config, aud: &str) -> Result<String, JwtError> {
|
|||
exp: now + 3600,
|
||||
};
|
||||
|
||||
let jwk = Jwk::from_encoding_key(&config.key, Algorithm::RS256)?;
|
||||
let key_id = jwk.thumbprint(ThumbprintHash::SHA256)?;
|
||||
let mut header = Header::new(Algorithm::RS256);
|
||||
header.kid = Some(key_id);
|
||||
|
||||
let secret = &config.key;
|
||||
let token = encode(&Header::new(Algorithm::RS256), &claims, secret)?;
|
||||
let token = encode(&header, &claims, secret)?;
|
||||
Ok(token)
|
||||
}
|
||||
|
||||
fn get_key_set(config: &JwtConfig) -> Result<JwkSet, JwtError> {
|
||||
let mut jwk = Jwk::from_encoding_key(&config.key, Algorithm::RS256)?;
|
||||
jwk.common.public_key_use = Some(PublicKeyUse::Signature);
|
||||
jwk.common.key_id = Some(jwk.thumbprint(ThumbprintHash::SHA256)?);
|
||||
Ok(JwkSet { keys: vec![jwk] })
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue