Device Detection and IP Intelligence for the 51Degrees Pipeline, in Rust

fodid-web-creator-context.rs File Reference

Classes

struct  Options
 Options that drive [run]. More...
struct  RedeemQuery
 The three parameters the page sends to /redeem. More...
struct  FakeCloud
 A cloud that answers the key list with one key in force since 2020, so it covers any identifier the test signs, and answers redeem with whatever the test scripted. More...

Functions

pub struct Options build_app (client:DidClient) -> Router
 Build the demo router, ready to serve.
pub async fn run (options:Options) -> anyhow::Result<()>
 Serve the demo over TCP until interrupted.
async fn home (State(demo):State< Demo >) -> Response
 The page, with a fresh single-use challenge per load.
fn page_with_find_out_more () -> String
 [PAGE] with a "Find out more" section, set apart by a rule, before its closing body tag.
struct RedeemQuery redeem (State(demo):State< Demo >, Query(query):Query< RedeemQuery >) -> Response
 The server-side step.
async fn redeem_with (client:&DidClient, query:&RedeemQuery) -> Response
 The lines a developer copies into their own server.
fn redeem_response (result:&RedeemResult, server_signature:&str) -> Response
 The cloud's answer in its own shape, built from the typed result, with serverSignature added.
fn client_error (error:ClientError) -> Response
 The error paths, as the page sees them.
fn errors_response (status:StatusCode, message:&str) -> Response
 A JSON body in the cloud's errors shape.
fn gateway_error (message:&str) -> Response
 A 502 with a JSON body naming the fault, for when the cloud could not be reached or its answer could not be read.
fn json_response (status:StatusCode, body:serde_json::Value) -> Response
async fn main () -> anyhow::Result<()>

Variables

const PAGE
 The demo page, embedded so the binary is self-contained.
const FIND_OUT_MORE
 The links the page and the console output end with.
const & str
const PAGE_CSS_ROUTE
 The route the demo page's relative stylesheet URL resolves to.
const DEFAULT_PORT
 The port the demo listens on when PORT is not set.
pub struct Options DidClient
 What every handler needs, carried as the router's state.
pub client
 The cloud client the server redeems through, built once at start-up from the resource key, the optional licence key and the endpoint.
pub pub address
 The socket address the server binds to.
fodid __pad0__
 The 51Did itself, in the URL-safe alphabet the page's links use.
fodid result
fodid challenge
mod tests
const RESOURCE_KEY

Function Documentation

◆ build_app()

pub struct Options build_app ( client:DidClient ) -> Router

Build the demo router, ready to serve.

It is returned rather than served so the test can drive it in process with tower::ServiceExt::oneshot while [run] serves it over TCP. The test builds the client over an injected transport, so no cloud is called.

◆ client_error()

fn client_error ( error:ClientError ) -> Response

The error paths, as the page sees them.

A host without the creator context answers 404 with a text body, which the page reports as not supported by this host. A 51Did the cloud refused answers 400 with the cloud's errors. Any other status the cloud sent is relayed with its body, and a cloud that could not be reached answers 502 with a JSON error naming the fault.

◆ errors_response()

fn errors_response ( status:StatusCode ,
message:& str ) -> Response

A JSON body in the cloud's errors shape.

◆ gateway_error()

fn gateway_error ( message:& str) -> Response

A 502 with a JSON body naming the fault, for when the cloud could not be reached or its answer could not be read.

The page shows the message.

◆ home()

async fn home ( State(demo):State< Demo > ) -> Response

The page, with a fresh single-use challenge per load.

The challenge is bound through both verification steps by the cloud, so a result verified under one page load cannot be redeemed under another.

◆ json_response()

fn json_response ( status:StatusCode ,
body:serde_json::Value  ) -> Response

◆ main()

async fn main ( ) -> anyhow::Result<()>

◆ page_with_find_out_more()

fn page_with_find_out_more ( ) -> String

[PAGE] with a "Find out more" section, set apart by a rule, before its closing body tag.

The section is added here so the page file stays the same as every other language's copy.

◆ redeem()

struct RedeemQuery redeem ( State(demo):State< Demo > ,
Query(query):Query< RedeemQuery >  ) -> Response

The server-side step.

The client's futures are not Send, because its transport is written for hosts without threads, and axum needs a handler whose future is, so the calls run on a blocking thread with a runtime of their own.

◆ redeem_response()

fn redeem_response ( result:& RedeemResult,
server_signature:& str ) -> Response

The cloud's answer in its own shape, built from the typed result, with serverSignature added.

A field the cloud did not send is not invented.

◆ redeem_with()

async fn redeem_with ( client:& DidClient,
query:& RedeemQuery ) -> Response

The lines a developer copies into their own server.

The licence key is held by the client and only there, so the browser never sees it, and the page receives the cloud's status and a JSON body in the cloud's own shape (signature, context, factors when present, verifiedAt, secondsSinceVerified) plus one extra field, serverSignature, with the outcome of this server's own offline signature check.

◆ run()

pub async fn run ( options:Options ) -> anyhow::Result<()>

Serve the demo over TCP until interrupted.

Variable Documentation

◆ __pad0__

fodid __pad0__

The 51Did itself, in the URL-safe alphabet the page's links use.

The parameter is named 51did on the wire, which is not a legal field name, so it is renamed here.

◆ address

pub pub address

The socket address the server binds to.

◆ challenge

fodid challenge

◆ client

pub client

The cloud client the server redeems through, built once at start-up from the resource key, the optional licence key and the endpoint.

◆ DEFAULT_PORT

const DEFAULT_PORT

The port the demo listens on when PORT is not set.

◆ DidClient

pub struct Options DidClient

What every handler needs, carried as the router's state.

The client is shared because the redeem handler moves a handle to a blocking thread.

◆ FIND_OUT_MORE

const FIND_OUT_MORE

The links the page and the console output end with.

◆ PAGE

const PAGE

The demo page, embedded so the binary is self-contained.

It is byte for byte the page every 51Degrees language example serves for this demo. Its relative stylesheet URL is served from the shared Rust example asset.

◆ PAGE_CSS_ROUTE

const PAGE_CSS_ROUTE

The route the demo page's relative stylesheet URL resolves to.

◆ RESOURCE_KEY

const RESOURCE_KEY

◆ result

fodid result

◆ str

const & str
Initial value:
= &[
("51Did", "/documentation/_identifiers_51_did.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-fodid-examples-src-bin-fodid-web-creator-context.rs&utm_term=find-out-more"),
("51Did inspector", "/developers/51did-inspector?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-fodid-examples-src-bin-fodid-web-creator-context.rs&utm_term=find-out-more"),
("Documentation", "/documentation/index.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-rust&utm_content=examples-fodid-examples-src-bin-fodid-web-creator-context.rs&utm_term=find-out-more"),
]

◆ tests

mod tests
Initial value:
{
use super::*