Allocate a new identity, and mint a new token for it.
(ctx: &(impl NodeDelegate + ControlStateDelegate + ?Sized))
| 182 | impl SpacetimeAuth { |
| 183 | /// Allocate a new identity, and mint a new token for it. |
| 184 | pub async fn alloc(ctx: &(impl NodeDelegate + ControlStateDelegate + ?Sized)) -> axum::response::Result<Self> { |
| 185 | // Generate claims with a random subject. |
| 186 | let subject = Uuid::new_v4().to_string().into(); |
| 187 | let claims = TokenClaims { |
| 188 | issuer: ctx.jwt_auth_provider().local_issuer().into(), |
| 189 | subject, |
| 190 | // Placeholder audience. |
| 191 | audience: ["spacetimedb".into()].into(), |
| 192 | extra: None, |
| 193 | }; |
| 194 | |
| 195 | let (claims, token) = claims.encode_and_sign(ctx.jwt_auth_provider()).map_err(log_and_500)?; |
| 196 | let creds = SpacetimeCreds::from_signed_token(token); |
| 197 | // Pulling out the payload should never fail, since we just made it. |
| 198 | Self::new(creds, claims).map_err(log_and_500) |
| 199 | } |
| 200 | |
| 201 | /// Get the auth credentials as headers to be returned from an endpoint. |
| 202 | pub fn into_headers(self) -> (TypedHeader<SpacetimeIdentity>, TypedHeader<SpacetimeIdentityToken>) { |
nothing calls this directly
no test coverage detected