示例#1
0
        // 有关配置身份验证的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // 将数据库上下文和用户管理器配置为对每个请求使用单个实例

            // 使应用程序可以使用 Cookie 来存储已登录用户的信息
            // 并使用 Cookie 来临时存储有关使用第三方登录提供程序登录的用户的信息
            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            var simpleSSOOption = new SimpleSSOAccountAuthenticationOptions
            {
                ClientId                = "3",
                ClientSecret            = "123",
                CallbackPath            = new PathString("/login/signin-simplesso"),
                TokenEndpoint           = "http://localhost:8550/token",
                AuthorizationEndpoint   = "http://localhost:8550/GrantCode/Authorize",
                UserInformationEndpoint = "http://localhost:8550/TicketUser/TicketMessage"
            };

            simpleSSOOption.Scope.Add("user-base");
            app.UseSimpleSSOAccountAuthentication(simpleSSOOption);


            // 取消注释以下行可允许使用第三方登录提供程序登录
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //    consumerKey: "",
            //    consumerSecret: "");

            //app.UseFacebookAuthentication(
            //    appId: "",
            //    appSecret: "");

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }
        /// <summary>
        /// Authenticate users using Microsoft Account
        /// </summary>
        /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param>
        /// <param name="options">Middleware configuration options</param>
        /// <returns>The updated <see cref="IAppBuilder"/></returns>
        public static IAppBuilder UseSimpleSSOAccountAuthentication(this IAppBuilder app, SimpleSSOAccountAuthenticationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            app.Use(typeof(SimpleSSOAccountAuthenticationMiddleware), app, options);
            return(app);
        }