Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. public partial class Startup
  2. {
  3. public void ConfigureAuth(IAppBuilder app)
  4. {
  5. app.CreatePerOwinContext(ApplicationDbContext.Create);
  6. app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
  7. app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
  8.  
  9. // Enable the application to use a cookie to store information for the signed in user
  10. // and to use a cookie to temporarily store information about a user logging in with a third party login provider
  11.  
  12. app.UseCookieAuthentication(new CookieAuthenticationOptions
  13. {
  14. AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
  15. LoginPath = new PathString("/Account/Login"),
  16. });
  17. app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
  18. app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
  19.  
  20. app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
  21. app.UseFacebookAuthentication(
  22. appId: "MeuAppID",
  23. appSecret: "MeuAppSecret");
  24.  
  25. // O que devo setar no FacebookAppId
  26. // Já Coloquei o Id da app do facebook mas não funcionou
  27.  
  28. if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("FacebookAppId")))
  29. {
  30. var facebookOptions = new FacebookAuthenticationOptions
  31. {
  32. AppId = ConfigurationManager.AppSettings.Get(""),
  33. AppSecret = ConfigurationManager.AppSettings.Get(""),
  34. Provider = new FacebookAuthenticationProvider
  35. {
  36. OnAuthenticated = (context) =>
  37. {
  38. context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook"));
  39. foreach (var x in context.User)
  40. {
  41. var claimType = string.Format("urn:facebook:{0}", x.Key);
  42. string claimValue = x.Value.ToString();
  43. if (!context.Identity.HasClaim(claimType, claimValue))
  44. context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook"));
  45.  
  46. }
  47. return Task.FromResult(0);
  48. }
  49. }
  50. };
  51. app.UseFacebookAuthentication(facebookOptions);
  52. }
  53. }
  54.  
  55. const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement