Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. public class RoomsAuthProvider : CredentialsAuthProvider
  2. {
  3. private int userId = 0;
  4.  
  5. public RoomsAuthProvider(AppSettings appSettings) : base(appSettings)
  6. {
  7. }
  8.  
  9. public RoomsAuthProvider()
  10. {
  11. }
  12.  
  13. public override bool TryAuthenticate(IServiceBase authService,
  14. string userName, string password)
  15. {
  16. if (password == "ValidPassword")
  17. {
  18. return true;
  19. }
  20.  
  21. else
  22. {
  23. return false;
  24. }
  25. }
  26.  
  27. public override IHttpResult OnAuthenticated(IServiceBase authService,
  28. IAuthSession session, IAuthTokens tokens,
  29. Dictionary<string, string> authInfo)
  30. {
  31. //Fill IAuthSession with data you want to retrieve in the app eg:
  32. session.FirstName = "some_firstname_from_db";
  33. //...
  34.  
  35. //Call base method to Save Session and fire Auth/Session callbacks:
  36. return base.OnAuthenticated(authService, session, tokens, authInfo);
  37.  
  38. //session.CreatedAt = DateTime.Now;
  39. //session.DisplayName = "CustomDisplayName" + userId;
  40. //session.IsAuthenticated = true;
  41. //session.UserAuthName = session.UserName;
  42. //session.UserAuthId = userId.ToString();
  43.  
  44. //Interlocked.Increment(ref userId);
  45.  
  46. //authService.SaveSession(session, SessionExpiry);
  47. //return null;
  48. }
  49. }
  50.  
  51. [Authenticate]
  52. public class ServerEventsService : Service
  53. {
  54. ...
  55. }
  56.  
  57. var client = new ServerEventsClient("http://localhost:1337/", "home")
  58. {
  59. OnConnect = OnConnect,
  60. OnCommand = HandleIncomingCommand,
  61. OnMessage = HandleIncomingMessage,
  62. OnException = OnException,
  63. OnHeartbeat = OnHeartbeat
  64. }.Start();
  65.  
  66. client.Connect().Wait();
  67.  
  68. var authResponse = client.Authenticate(new Authenticate
  69. {
  70. provider = "credentials",
  71. UserName = "test@gmail.com",
  72. Password = "p@55w0rd",
  73. RememberMe = true,
  74. });
  75.  
  76. client.ServiceClient.Post(new PostChatToChannel
  77. {
  78. Channel = "home", // The channel we're listening on
  79. From = client.SubscriptionId, // Populated after Connect()
  80. Message = "Hello, World!",
  81. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement