forked from daattali/beautiful-jekyll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msal.html
108 lines (90 loc) · 3.04 KB
/
msal.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html>
<html>
<head>
<title>Authenticate with MSAL.js</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style>body{font:normal normal normal 14px/1.5em "Century Gothic", sans-serif;}</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://alcdn.msauth.net/lib/1.1.0/js/msal.js"></script>
<script type="text/javascript">
$(document).ready(function() {
"use strict";
// Assign variables
const msalConfig = {
auth: {
// clientId: 'c4a602f1-be44-4916-ad57-27245eca17fd',
clientId: '49d7da3f-5378-48f1-b78d-5cfd981784d5',
authority: "https://login.microsoftonline.com/9e1c4e36-4f81-4b67-b7cd-ed19cb8c61b5/"
// ,
// "optionalClaims":
// {
// "idToken": [
// {
// "name": "extension_b88ed72f651948889656244039339c5f_stuExtensionAttriibute1",
// "source": "user",
// "essential": true,
// "additionalProperties": []
// }
// ]
// }
}
};
const msalInstance = new Msal.UserAgentApplication(msalConfig);
msalInstance.handleRedirectCallback((error, response) => {
// handle redirect response or error
});
var loginRequest = {
scopes: [
//"openid",
"profile",
"User.Read", "User.Read.All"
,"User.ReadBasic.All"], // optional Array<string>
prompt: 'select_account'
};
$('#message').html("starting login....");
msalInstance.loginPopup(loginRequest)
.then(response => {
// handle response
$('#message').html("welcome " + response.idTokenClaims.preferred_username);
$('#claims').html("<a href='https://jwt.ms/#id_token=" +response.idToken.rawIdToken + "' target='_blank'>jwt.ms</a>");
console.log(response.idTokenClaims);
var $a = "";
// $.each( response.idTokenClaims, function( key, value ) {
// $a+= key + ": " + value;
// });
// $('claims').html( $a );
})
.catch(err => {
// handle error
console.log(err);
$('#message').html("error");
});
});
</script>
</head>
<body>
<!-- MSAL.JS https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-core/README.md -->
<h1>
Welcome to MSAL.JS demo
</h1>
<a href='https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-app-types#single-page-apps-javascript'>Microsoft identity platform OAuth2 2.0 implicit flow diagram</a>
<br/>
<a href='https://aka.ms/aadv2'>msal.js getting started</a>
<br/>
<a href='https://github.com/Azure-Samples/active-directory-javascript-graphapi-v2'>Call Graph API from a JavaScript Single Page Application using msal.js</a>
<h2>
<div id="message">
startup
</div>
</h2>
<div id="claims"></div>
<div>
<h2>Setup steps:</h2>
<ul>
<li>Add app registration</li>
<li> ensure the following is set in the manifest "oauth2AllowIdTokenImplicitFlow": true,
"oauth2AllowImplicitFlow": true,
</li>
</div>
</body>
</html>