Google login in Angular 7 with .NET Core API

前端 未结 4 1051
北荒
北荒 2020-12-30 11:21

I\'m trying to implement Google login in my Angular application. If I try to call api endpoint for external login server return 405 error code like this:

4条回答
  •  独厮守ぢ
    2020-12-30 12:05

    I had a similar problem, and since you said you already have CORS all set up in the back end, Angular not adding credentials in the API requests might be the problem. Something the browser does when you type the api endpoint in the url bar. You can use angular interceptors for adding credentials in every request. Check this: https://angular.io/guide/http#intercepting-requests-and-responses

    And for your particular case, this may work:

    export class CookieInterceptor implements HttpInterceptor {
    
      intercept(request: HttpRequest, next: HttpHandler): Observable> {
        request = request.clone({
          withCredentials: true
        });
        return next.handle(request);
      }
    }
    

提交回复
热议问题