c# - Get user name and email using Microsoft.Identity.Client -
i using package https://www.nuget.org/packages/microsoft.identity.client authenticate user, auth working fine, problem is, thinking use token after login user name , email (as need not access inbox, contacts, , calendar; link user rol using email). problem is, when token, i long string userid (i guess encrypted). there way can use package email?
this section token back
public sessiontokencache(string userid, httpcontextbase httpcontext) { this.userid = userid; cacheid = userid + "_tokencache"; this.httpcontext = httpcontext; beforeaccess = beforeaccessnotification; afteraccess = afteraccessnotification; load(); } this tutorial followed https://dev.outlook.com/restapi/tutorial/dotnet
once have token, maybe can use graph api details logged on user? result json can used extract bits want.
public static async task<string> getuserdata(string token) { //get data api httpclient client = new httpclient(); httprequestmessage message = new httprequestmessage(httpmethod.get, "https://graph.microsoft.com/v1.0/me"); message.headers.authorization = new system.net.http.headers.authenticationheadervalue("bearer", token); httpresponsemessage response = await client.sendasync(message); string responsestring = await response.content.readasstringasync(); if (response.issuccessstatuscode) return responsestring; else return null; }
Comments
Post a Comment