Graph Delegated Authorization + DataVerse
PerigeeApplication.ApplicationNoInit("GraphDemo", (c) =>
{
//Graph and token endpoint
var dvGraph = new GraphClient(
c.GetValue<string>("graph:tenant"),
c.GetValue<string>("graph:client"),
c.GetValue<string>("graph:secret"),
c.GetValue<string>("graph:scope"),
c.GetValue<string>("graph:redirect"),
"",
c.GetLogger<Program>());
//Add token receive endpoint
c.AddMinimalAPI("TokenReceiver", 7201, (w) => {
w.MapGet("/api/token", ([FromQuery] string code, GraphClient graph) => { CredentialStore.RefreshAuthorizationCode(graph.credentialName, code); return Results.Ok("Got the new code! Thanks!"); }); },
(b,s) => s.AddSingleton<GraphClient>(dvGraph));
//Await a valid credential on load
var cred = CredentialStore.AwaitValidCredential(dvGraph.credentialName, c.GetCancellationToken()).GetAwaiter().GetResult();
c.GetLogger<_PerigeeStartup>().LogInformation("Authorized Account: {acc}", cred.JWTGetValue(cred.DecodeJWT(cred.Authorization), "unique_name"));
});For DataVerse
Last updated

