1

I'm getting this error:

Access to XMLHttpRequest at 'https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize/.well-known/openid-configuration' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

when trying to redirect to azure for login.

Here's the service:

export class AuthService {
private _userManager: UserManager;

constructor(private http: HttpClient) {
    const config = {
        authority: Constants.stsAuthority,
        client_id: Constants.clientId,
        redirect_uri: `${Constants.clientRoot}assets/oidc-login-redirect.html`,
        scope: 'openid profile',
        response_type: 'id_token token',
        post_logout_redirect_uri: `${Constants.clientRoot}?postLogout=true`,
        userStore: new WebStorageStateStore({ store: window.localStorage })
      };
    this._userManager = new UserManager(config)
 }

 login(): Promise<any>{
     return this._userManager.signinRedirect();
 }

}

I'm sure I registered correctly my localhost url. Yet, I'm getting that error. So far, I didn't see any documentation dealing with that.

Thanks for helping

enter image description here

Richard77
  • 17,505
  • 36
  • 124
  • 222
  • http://restlet.com/blog/2016/09/27/how-to-fix-cors-problems/ , your azure server should allow requests from different domain – dota2pro Sep 06 '19 at 19:31
  • I'm not trying to access my azure application. I'm trying to authenticate using `Active Directory.` – Richard77 Sep 06 '19 at 20:03
  • Well my point was CORS is the server's problem it doesn't have to do anything with angular/javascript – dota2pro Sep 06 '19 at 20:20

1 Answers1

2

https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize/.well-known/openid-configuration is not a valid URL.

Probably your authority is configured wrong. It should be just https://login.microsoftonline.com/tenant-id.

juunas
  • 41,356
  • 5
  • 86
  • 118
  • the `url` was the culprit. Yet, that's what was shown the tutorial I watched on YouTube. Now I'm getting a different error `AADSTS90002: Tenant not found. This may happen if there are no active subscriptions for the tenant. Check with your subscription administrator.`. However, at least I'm being redirected to Azure. Thank you so much. – Richard77 Sep 07 '19 at 15:51
  • 1
    Did you replace tenant-id with your actual tenant id? – juunas Sep 07 '19 at 17:08
  • Yes. I went to `Properties` page and copied the value of `Directory ID`. What's strange is that it's complaining about a tenant ID that I didn't send, i.e. My `Directory ID` is different from the `Tenant ID` AD complaints that it can't find. – Richard77 Sep 07 '19 at 22:49
  • 1
    I see now why I was getting that error. It's because I was using my free account to test the concept. Now I'm using my company subscription, so I solved the problem. Thank you again. – Richard77 Sep 11 '19 at 00:30