/// <summary> /// Initializes a new instance of the <see cref="Pusher" /> class. /// </summary> /// <param name="appId">The app id.</param> /// <param name="appKey">The app key.</param> /// <param name="appSecret">The app secret.</param> /// <param name="options">Additional options to be used with the instance e.g. setting the call to the REST API to be made over HTTPS.</param> public Pusher(string appId, string appKey, string appSecret, IPusherOptions options) { ThrowArgumentExceptionIfNullOrEmpty(appId, "appId"); ThrowArgumentExceptionIfNullOrEmpty(appKey, "appKey"); ThrowArgumentExceptionIfNullOrEmpty(appSecret, "appSecret"); if (options == null) { options = new PusherOptions(); } _appId = appId; _appKey = appKey; _appSecret = appSecret; _options = options; }
/// <summary> /// Initializes a new instance of the <see cref="Pusher" /> class. /// </summary> /// <param name="appId">The app id.</param> /// <param name="appKey">The app key.</param> /// <param name="appSecret">The app secret.</param> /// <param name="options">(Optional)Additional options to be used with the instance e.g. setting the call to the REST API to be made over HTTPS.</param> public Pusher(string appId, string appKey, string appSecret, IPusherOptions options = null) { ThrowArgumentExceptionIfNullOrEmpty(appId, "appId"); ThrowArgumentExceptionIfNullOrEmpty(appKey, "appKey"); ThrowArgumentExceptionIfNullOrEmpty(appSecret, "appSecret"); if (options == null) { options = new PusherOptions(); } _appKey = appKey; _appSecret = appSecret; _options = options; _factory = new AuthenticatedRequestFactory(appKey, appId, appSecret); }
public AuthModule() { PusherServer.PusherOptions options = new PusherServer.PusherOptions { EncryptionMasterKey = Convert.FromBase64String(EncryptionMasterKeyText), Cluster = Config.Cluster, }; var provider = new PusherServer.Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret, options); Post["/auth/{username}", ctx => ctx.Request.Form.channel_name && ctx.Request.Form.socket_id] = _ => { Console.WriteLine($"Processing auth request for '{Request.Form.channel_name}' channel, for socket ID '{Request.Form.socket_id}'"); string channelName = Request.Form.channel_name; string socketId = Request.Form.socket_id; string authData = null; if (Channel.GetChannelType(channelName) == ChannelTypes.Presence) { var channelData = new PresenceChannelData { user_id = socketId, user_info = new { Name = _.username.ToString() } }; authData = provider.Authenticate(channelName, socketId, channelData).ToJson(); } else { authData = provider.Authenticate(channelName, socketId).ToJson(); } if (Channel.GetChannelType(channelName) == ChannelTypes.PrivateEncrypted) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed SendSecretMessageAsync(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } return(authData); }; }
private async Task SendSecretMessageAsync() { await Task.Delay(5000).ConfigureAwait(false); PusherServer.PusherOptions options = new PusherServer.PusherOptions { EncryptionMasterKey = Convert.FromBase64String(EncryptionMasterKeyText), Cluster = Config.Cluster, }; string channelName = "private-encrypted-channel"; string eventName = "secret-event"; var provider = new PusherServer.Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret, options); string secretMessage = $"sent secret at {DateTime.Now} on '{channelName}' using event '{eventName}'."; await provider.TriggerAsync(channelName, eventName, new { Name = nameof(AuthModule), Message = secretMessage, }).ConfigureAwait(false); Console.WriteLine(secretMessage); }
public async Task <string> AuthorizeAsync(string channelName, string socketId) { string authData = null; double delay = (await LatencyInducer.InduceLatencyAsync(MinLatency, MaxLatency)) / 1000.0; Trace.TraceInformation($"{this.GetType().Name} paused for {Math.Round(delay, 3)} second(s)"); await Task.Run(() => { PusherServer.PusherOptions options = new PusherServer.PusherOptions { EncryptionMasterKey = _encryptionKey, Cluster = Config.Cluster, }; var provider = new PusherServer.Pusher(Config.AppId, Config.AppKey, Config.AppSecret, options); if (channelName.StartsWith("presence-")) { var channelData = new PresenceChannelData { user_id = socketId, user_info = new FakeUserInfo { name = _userName } }; authData = provider.Authenticate(channelName, socketId, channelData).ToJson(); } else { authData = provider.Authenticate(channelName, socketId).ToJson(); } if (channelName.Contains(TamperToken)) { authData = authData.Replace("1", "2"); } }).ConfigureAwait(false); return(authData); }