mmacneil / AngularASPNETCore2WebApiAuth

Sample project demonstrating jwt-based authentication with an Angular (v5.2.1) frontend and ASP.NET Core 2 WebApi. Includes both local user registration with .NET Core Identity membership and facebook login scenarios.
https://fullstackmark.com/post/13/jwt-authentication-with-aspnet-core-2-web-api-angular-5-net-core-identity-and-facebook-login
MIT License
470 stars 239 forks source link

Facebook Login Autorefreshes and loses token #13

Closed matt-goldman closed 4 years ago

matt-goldman commented 5 years ago

Description

When using Facebook login, the window that opens sends the message back to the Facebook login component. Using a very quickly captured screenshot I can confirm that this contains the 'status' variable (showing true) and the access token. However, this page (Facebook login component) then immediately refreshes, resulting in the token being lost and the line const result = JSON.parse(message.data); results in an undefined error.

Expected Behavior

The page should not refresh, the message should be parsed and the token sent to the facebookLogin function in the user service.

Current Behavior

Page refreshes and token is lost.

Steps to Reproduce

1.Build project as per tutorial

  1. Verify code against Github repository
  2. Run backend and client
  3. Click Facebook Login on home screen, then the Login with Facebook button
  4. Login to Facebook (if not already)
matt-goldman commented 5 years ago

Basically turned out to be a typo in my code. Apologies for the unnecessary issue. Weirdly what compounded it for me was that I couldn't hit the breakpoint in my external auth controller (I would have expected the issue in question to result in a bad model state) but instead its as if the controller never got reached.

matt-goldman commented 5 years ago

Sorry spoke to soon. The problem seems to be with this line:

var appAccessTokenResponse = await Client.GetStringAsync($"https://graph.facebook.com/oauth/access_token?client_id={_fbAuthSettings.AppId}&client_secret={_fbAuthSettings.AppSecret}&grant_type=client_credentials");

I've done some testing to ensure the url is getting translated correctly (which it is), but sending a get request to this url results in a 500 internal server error back from Facebook:

{
    "error": {
        "message": "An unknown error has occurred.",
        "type": "OAuthException",
        "code": 1,
        "fbtrace_id": "xxxx"
    }
}