-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.aspx.cs
48 lines (40 loc) · 1.46 KB
/
default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Http;
using Newtonsoft.Json.Linq;
namespace msalAuth
{
public partial class _default : System.Web.UI.Page
{
string token = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.Count > 0)
{
if (Request.QueryString["tk"] != "")
{
token = Request.QueryString["tk"];
using (var client = new HttpClient())
{
var url = "https://graph.microsoft.com/v1.0/me/";
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
var response = client.GetAsync(url).Result;
var responseContent = response.Content;
string responseString = responseContent.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
JObject jObject = JObject.Parse(responseString);
Label1.Text = "Welcome " + jObject["displayName"].ToString();
}
else
Label1.Text = responseString + "[" + token + "]";
}
}
}
}
}
}