Get ExtraData from MVC5 framework OAuth/OWin identity provider with external auth provider

前端 未结 7 2011
旧巷少年郎
旧巷少年郎 2020-11-30 20:22

I\'m trying to use the new MVC5 framework in VS 2013 preview.

The membership authentication framework has been overhauled and replaced with OWin.

<
7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 21:06

    So unfortunately this is not super straightforward, one way you can do this is to hook the GoogleProvider Authenticated event and add a custom claim to the Claims Identity with the avatar:

    public class MyGoogleProvider : GoogleAuthenticationProvider {
        public override Task Authenticated(GoogleAuthenticatedContext context) {
            context.Identity.AddClaim(new Claim("avatarClaim", ""));
            return base.Authenticated(context);
        }
    }
    
    app.UseGoogleAuthentication(new GoogleAuthenticationOptions() { Provider = new MyGoogleProvider() });
    

    Then inside of your AccountController, when the external identity is extracted, you can take this avatar claim and store it into your user object for use later.

提交回复
热议问题