Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Startup
- {
- public void ConfigureAuth(IAppBuilder app)
- {
- app.CreatePerOwinContext(ApplicationDbContext.Create);
- app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
- app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
- // Enable the application to use a cookie to store information for the signed in user
- // and to use a cookie to temporarily store information about a user logging in with a third party login provider
- app.UseCookieAuthentication(new CookieAuthenticationOptions
- {
- AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
- LoginPath = new PathString("/Account/Login"),
- });
- app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
- app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
- app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
- app.UseFacebookAuthentication(
- appId: "MeuAppID",
- appSecret: "MeuAppSecret");
- // O que devo setar no FacebookAppId
- // Já Coloquei o Id da app do facebook mas não funcionou
- if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("FacebookAppId")))
- {
- var facebookOptions = new FacebookAuthenticationOptions
- {
- AppId = ConfigurationManager.AppSettings.Get(""),
- AppSecret = ConfigurationManager.AppSettings.Get(""),
- Provider = new FacebookAuthenticationProvider
- {
- OnAuthenticated = (context) =>
- {
- context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook"));
- foreach (var x in context.User)
- {
- var claimType = string.Format("urn:facebook:{0}", x.Key);
- string claimValue = x.Value.ToString();
- if (!context.Identity.HasClaim(claimType, claimValue))
- context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook"));
- }
- return Task.FromResult(0);
- }
- }
- };
- app.UseFacebookAuthentication(facebookOptions);
- }
- }
- const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement