Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RoomsAuthProvider : CredentialsAuthProvider
- {
- private int userId = 0;
- public RoomsAuthProvider(AppSettings appSettings) : base(appSettings)
- {
- }
- public RoomsAuthProvider()
- {
- }
- public override bool TryAuthenticate(IServiceBase authService,
- string userName, string password)
- {
- if (password == "ValidPassword")
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public override IHttpResult OnAuthenticated(IServiceBase authService,
- IAuthSession session, IAuthTokens tokens,
- Dictionary<string, string> authInfo)
- {
- //Fill IAuthSession with data you want to retrieve in the app eg:
- session.FirstName = "some_firstname_from_db";
- //...
- //Call base method to Save Session and fire Auth/Session callbacks:
- return base.OnAuthenticated(authService, session, tokens, authInfo);
- //session.CreatedAt = DateTime.Now;
- //session.DisplayName = "CustomDisplayName" + userId;
- //session.IsAuthenticated = true;
- //session.UserAuthName = session.UserName;
- //session.UserAuthId = userId.ToString();
- //Interlocked.Increment(ref userId);
- //authService.SaveSession(session, SessionExpiry);
- //return null;
- }
- }
- [Authenticate]
- public class ServerEventsService : Service
- {
- ...
- }
- var client = new ServerEventsClient("http://localhost:1337/", "home")
- {
- OnConnect = OnConnect,
- OnCommand = HandleIncomingCommand,
- OnMessage = HandleIncomingMessage,
- OnException = OnException,
- OnHeartbeat = OnHeartbeat
- }.Start();
- client.Connect().Wait();
- var authResponse = client.Authenticate(new Authenticate
- {
- provider = "credentials",
- UserName = "test@gmail.com",
- Password = "p@55w0rd",
- RememberMe = true,
- });
- client.ServiceClient.Post(new PostChatToChannel
- {
- Channel = "home", // The channel we're listening on
- From = client.SubscriptionId, // Populated after Connect()
- Message = "Hello, World!",
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement