clechner77
11/22/2016 - 5:48 AM

plain javascript for adal for js

plain javascript for adal for js

<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.11/js/adal.min.js"></script>

<body>
<a href="#" onclick="login();">login</a>
<a href="#" onclick="getToken()">access token</a>
<a href="#" onclick="getUser()">get user</a>
</body>
<script type="text/javascript">
	var configOptions = {
		tenant: "a75c8de2-xxxx-xxxx-xxxx-4c07fe699a0b", // Optional by default, it sends common
        clientId: "90e54701-xxxx-xxxx-xxxx-c2d9b01417f3",
        postLogoutRedirectUri: window.location.origin,
	}
	window.authContext = new AuthenticationContext(configOptions);

	var isCallback = authContext.isCallback(window.location.hash);
    authContext.handleWindowCallback();

    function getToken(){
    	authContext.acquireToken("https://graph.microsoft.com",function(error, token){
			console.log(error);
			console.log(token);
		})
    }
	function login(){
		authContext.login();
	}
	function getUser(){
		var user = authContext.getCachedUser();
		console.log(user);
	}
</script>