Skip to content Skip to sidebar Skip to footer

OAuth2 Access Origin Error

I Request an authorization code from OAuth2 Server. My purpose is to authorize user with my microsoft App. Refered Document My attempt for get Call: function httpGet(){ va

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:

Here is the code sample to acquire access token from Microsoft Graph:

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

<body>
<a href="#" onclick="login();">login</a>
<a href="#" onclick="getToken()">access token</a>
</body>
<script type="text/javascript">
    var configOptions = {
        tenant: "<tenant_id>", // Optional by default, it sends common
        clientId: "<client_id>",
        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();
    }
</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"