Class FederationAuth
Request authentication between servers: the sender signs the method, URI, both server names and the JSON body, and puts the signature in an X-Matrix Authorization header.
Inherited Members
Namespace: Uniform.Matrix.Protocol.Server
Assembly: Uniform.Matrix.Protocol.Server.dll
Syntax
public static class FederationAuth
Examples
XMatrixAuthorization header = FederationAuth.Sign("GET", "/_matrix/federation/v1/query/profile?user_id=%40bob%3Ab.org", "a.org", "b.org", null, keyId, seed);
bool valid = FederationAuth.Verify("GET", uri, header, "b.org", null, publicKeyOfA);
Methods
| Edit this page View SourceParse(string?)
Parse an Authorization header value; return null when it is not a complete X-Matrix one.
Declaration
public static XMatrixAuthorization? Parse(string? header)
Parameters
| Type | Name | Description |
|---|---|---|
| string | header |
Returns
| Type | Description |
|---|---|
| XMatrixAuthorization |
Remarks
Parameter names are case-insensitive and values may be quoted or not, as the spec allows; unknown parameters are ignored.
Sign(string, string, string, string, JsonNode?, string, string)
Return the authorization of a request.
Declaration
public static XMatrixAuthorization Sign(string method, string uri, string origin, string destination, JsonNode? content, string keyId, string secret)
Parameters
| Type | Name | Description |
|---|---|---|
| string | method | HTTP method, e.g. |
| string | uri | Path and query as sent, starting with |
| string | origin | Sending server, this one. |
| string | destination | Receiving server. |
| JsonNode | content | JSON body, or null for requests without one. |
| string | keyId | Signing key ID. |
| string | secret | Ed25519 seed, base64. |
Returns
| Type | Description |
|---|---|
| XMatrixAuthorization |
Verify(string, string, XMatrixAuthorization, string, JsonNode?, string)
Return whether authorization validly signs the request for serverName, with the origin's key publicKey.
Declaration
public static bool Verify(string method, string uri, XMatrixAuthorization authorization, string serverName, JsonNode? content, string publicKey)
Parameters
| Type | Name | Description |
|---|---|---|
| string | method | HTTP method as received. |
| string | uri | Path and query as received. |
| XMatrixAuthorization | authorization | Parsed header. |
| string | serverName | This server; a header for another destination is not valid here. |
| JsonNode | content | JSON body, or null. |
| string | publicKey | Origin's public key of KeyId. |
Returns
| Type | Description |
|---|---|
| bool |