Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. internal class SelfHost : AppSelfHostBase
  2. {
  3. public SelfHost() : base("HttpListener Self-Host", typeof(ServerEventsService).Assembly)
  4. {
  5. }
  6.  
  7. public override void Configure(Container container)
  8. {
  9. Plugins.Add(new ServerEventsFeature
  10. {
  11. LimitToAuthenticatedUsers = true,
  12. NotifyChannelOfSubscriptions = false,
  13. OnHeartbeatInit = req =>
  14. {
  15. var userSession = req.GetSession();
  16. var sessionKey = SessionFeature.GetSessionKey(req.GetSessionId());
  17. }
  18. });
  19.  
  20. container.Register<ICacheClient>(new MemoryCacheClient());
  21.  
  22. Plugins.Add(new AuthFeature(() => new AuthUserSession(),
  23. new IAuthProvider[]
  24. {
  25. //new StreamSecurityAuthProvider()
  26. new CredentialsAuthProvider
  27. {
  28. SessionExpiry = TimeSpan.FromSeconds(30),
  29. SkipPasswordVerificationForInProcessRequests = true,
  30. },
  31. })
  32. );
  33.  
  34. var userRep = new InMemoryAuthRepository();
  35. container.Register<IUserAuthRepository>(userRep);
  36.  
  37. string hash;
  38. string salt;
  39. var pwd = "ValidPassword";
  40.  
  41. new SaltedHash().GetHashAndSaltString(pwd, out hash, out salt);
  42. userRep.CreateUserAuth(new UserAuth
  43. {
  44. Id = 3,
  45. DisplayName = "CustomDisplayName2",
  46. Email = "test2@gmail.com",
  47. UserName = "CustomUserName2",
  48. FirstName = "FirstName2",
  49. LastName = "LastName2",
  50. PasswordHash = hash,
  51. Salt = salt,
  52. }, pwd);
  53. }
  54. }
  55.  
  56. _mainClient = new ServerEventsClient(baseUrl, "home");
  57.  
  58. var authResponse = _mainClient.Authenticate(new Authenticate
  59. {
  60. provider = "credentials",
  61. UserName = "CustomUserName2",
  62. Password = "ValidPassword",
  63. //Password = "wfjuwheiu",
  64. RememberMe = false,
  65. });
  66.  
  67. mainClient.Connect().Wait();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement