MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / alloc

Method alloc

crates/client-api/src/auth.rs:184–199  ·  view source on GitHub ↗

Allocate a new identity, and mint a new token for it.

(ctx: &(impl NodeDelegate + ControlStateDelegate + ?Sized))

Source from the content-addressed store, hash-verified

182impl 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>) {

Callers

nothing calls this directly

Calls 5

encode_and_signMethod · 0.80
newFunction · 0.50
to_stringMethod · 0.45
local_issuerMethod · 0.45
jwt_auth_providerMethod · 0.45

Tested by

no test coverage detected