Oauth2 Access Origin Error
Solution 1:
To integrate AAD in javascript, we suggest you to use azure-activedirectory-library-for-js which is a library in javascript for frontend to integrate AAD with a ease.
There are 2 options we need to pay attention on before we use ADAL for JS:
- According the node at https://github.com/OfficeDev/O365-jQuery-CORS#step-6--run-the-sample:
Note This sample will not work in Internet Explorer. Please use a different browser, such as Google Chrome. ADAL.js uses an iframe to get CORS API tokens for resources other than the SPA's own backend. These iframe requests require access to the browser's cookies to authenticate with Azure Active Directory. Unfortunately, cookies are not accessible to Internet Explorer when the app is running in localhost.
- Enable the
oauth2AllowImplicitFlow
of your Azure AD application. Refer to https://crmdynamicsblog.wordpress.com/2016/03/17/response-type-token-is-not-enabled-for-the-application-2/ for the detailed steps.
Here is the code sample to acquire access token from Microsoft Graph:
<scriptsrc="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.10/js/adal.min.js"></script><body><ahref="#"onclick="login();">login</a><ahref="#"onclick="getToken()">access token</a></body><scripttype="text/javascript">var configOptions = {
tenant: "<tenant_id>", // Optional by default, it sends commonclientId: "<client_id>",
postLogoutRedirectUri: window.location.origin,
}
window.authContext = newAuthenticationContext(configOptions);
var isCallback = authContext.isCallback(window.location.hash);
authContext.handleWindowCallback();
functiongetToken(){
authContext.acquireToken("https://graph.microsoft.com",function(error, token){
console.log(error);
console.log(token);
})
}
functionlogin(){
authContext.login();
}
</script>
Solution 2:
Without using any frontend
google libraries I came up with solution.
window.open("url")
After complete the authentication I get the code
from url params
and send it backend
and achieve the access token, refersh token.......etc,
Post a Comment for "Oauth2 Access Origin Error"