带有承载令牌和Facebook身份验证的WebApi2 . 在IAppBuilder属性中找不到SignInAsAuthenticationType的默认值

loading...


0

使用Bearer Token OAuth配置Web API 2项目后,一切正常 . 我设法通过/ Token获得令牌 . 当我添加Facebook身份验证时,虽然它开始提示“在 IAppBuilder 属性中找不到 SignInAsAuthenticationType 的默认值” . 错误 . 我保证我已经为令牌和Facebook身份验证添加了 SignInAsAuthentication 类型,并且它会继续 . 我哪里错了?

public void ConfigureAuth(IAppBuilder app)
    {
        _dataProtectionProvider = app.GetDataProtectionProvider();
        IUnityContainer container = UnityBootstrapper.Container;
        container.RegisterInstance(DataProtectionProvider);

        BootstrapperUnityResolver dependencyResolver = new BootstrapperUnityResolver(container);

        // Configure the db context and user manager to use a single instance per request
        app.CreatePerOwinContext(() => ApplicationDbContext.Create());
        app.CreatePerOwinContext(() => (ApplicationUserManager)dependencyResolver.GetService(typeof(ApplicationUserManager)));
        app.CreatePerOwinContext(() => (ApplicationSignInManager)dependencyResolver.GetService(typeof(ApplicationSignInManager)));

        PublicClientId = "self";
        OAuthServerOptions = new OAuthAuthorizationServerOptions
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/Token"),
            AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
            Provider = new ApplicationOAuthProvider(PublicClientId),
            AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30)
        };
        app.SetDefaultSignInAsAuthenticationType(OAuthDefaults.AuthenticationType);

        //app.UseOAuthBearerTokens(OAuthServerOptions);

        app.UseOAuthAuthorizationServer(OAuthServerOptions);
        OAuthAuthenticationOptions = new OAuthBearerAuthenticationOptions
        {
            Provider = new OAuthBearerAuthenticationProvider()
        };
        app.UseOAuthBearerAuthentication(OAuthAuthenticationOptions);

        var facebookAuthenticationOptions = new FacebookAuthenticationOptions();
        facebookAuthenticationOptions.AppId = "***";
        facebookAuthenticationOptions.AppSecret = "*****";
        facebookAuthenticationOptions.Provider = new FacebookAuthenticationProvider()
        {
            OnAuthenticated = async ctx =>
            {
                var token = ctx.AccessToken;

                var id = ctx.Id;
                var email = ctx.User["email"];

                ctx.Identity.AddClaim(new Claim("urn:myWebSite:AuthorityId", "1", ClaimValueTypes.String, "Facebook"));

                if (id != null)
                    ctx.Identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, id.ToString(), ClaimValueTypes.String, "Facebook"));
                if (email != null)
                    ctx.Identity.AddClaim(new Claim(ClaimTypes.Email, email.ToString(), ClaimValueTypes.String, "Facebook"));

                ctx.Identity.AddClaim(new Claim("fb.token", token));
            }
        };

        facebookAuthenticationOptions.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalBearer;
        app.UseFacebookAuthentication(facebookAuthenticationOptions);
    }

loading...

0回答

No Data

评论

暂时没有评论!