Base solution for your next web application
Open Closed

CORS ORIGIN problem with Office365 in AngularJS 6. #7125


User avatar
0
qbd created

I am implementing Office365 login auhtentication in SinglePageApplication-(.NET Core + Angular6) but I am getting below error... "Access to XMLHttpRequest at 'https://login.microsoftonline.com/{tenantid}/oauth2/token' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."

I am able to access this url "https://login.microsoftonline.com/{tenantid}/oauth2/token'" from post man and i am getting the required result .

Could you please help me to resolve this issue?

Thanks in advance.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    How did you implement it?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    qbd created

    I updated below code in appsettings.json file,

    "App": { "ServerRootAddress": "http://localhost:22742/", "ClientRootAddress": "http://localhost:4200/", "CorsOrigins": "http://localhost:4200,http://localhost:49152,https://login.microsoftonline.com" },

    I created Office365Login.component.js file and implemented below code

    let options_: any = { client_id: client_id, client_secret: client_secret, redirect_uri: redirect_uri, code: authorization_code, grant_type: authorization_code,

    headers: new HttpHeaders({
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": " POST, OPTIONS",
                "Access-Control-Allow-Headers": "Origin, Content-Type, X-Auth-Token",
                "Content-Type": "application/x-www-form-urlencoded",
        })
    

    }; //Here we are calling the office365 token api. this.http.request("post", "https://login.microsoftonline.com/{tenantid}/oauth2/token", options).subscribe(result => { console.log(result); });

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    qbd created

    We are not able to find the solution for cross origin issue. If any one knows please let us know.

    Thanks in advance!

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    qbd created

    We found the solution for single page application (AngularJS), any way we deicded to implement on server side for security reason.

    Thanks all for response.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)