示例#1
0
        //private ILog _log;
        public RevOAuthModule(IPushHub pushub)
            : base("RevOAuth")
        {
            Post["/"] = p =>
            {
                //_log = log;
                var revoauth = this.Bind <RevOAuthInfo>();
                if (!string.IsNullOrEmpty(revoauth.ConnectionId))
                {
                    pushub.ConnectionId = revoauth.ConnectionId;
                }

                RevOAuthRequest revOAuthReq = new RevOAuthRequest();
                string          revAuthUrl  = revOAuthReq.GetRevOAuthRequestUrl(revoauth.RevUrl.TrimEnd('/'), revoauth.ApiKey, revoauth.ApiSecret, revoauth.RedirectUri.TrimEnd('/'));
                if (revOAuthReq.Error)
                {
                    pushub.SendError(revAuthUrl);
                }
                return(revAuthUrl);
            };

            Get["/HostUrl"] = p =>
            {
                return(RevOAuthApp.Common.Configuration.RevOAuthConfigurationSection.GetConfig().Url);
            };

            Post["/ConnectionID"] = p =>
            {
                var pushHubConnection = this.Bind <PushHubConnection>();
                pushub.ConnectionId = pushHubConnection.Connection;
                return(Negotiate.WithStatusCode(Nancy.HttpStatusCode.OK));
            };

            Post["/RevToken"] = p =>
            {
                //_log = log;
                var revoauth = this.Bind <RevOAuthToken>();
                if (!string.IsNullOrEmpty(revoauth.ConnectionId))
                {
                    pushub.ConnectionId = revoauth.ConnectionId;
                }

                RevOAuthRequest revOAuthReq = new RevOAuthRequest();

                string revAuthToken = string.Empty;
                if (!string.IsNullOrEmpty(revoauth.Code))
                {
                    revAuthToken = revOAuthReq.GetRevOAuthToken(revoauth.ApiKey, revoauth.RedirectUri, revoauth.Code, revoauth.RevUrl);
                }
                else
                {
                    pushub.SendError("Not able to get code!");
                }

                if (revOAuthReq.Error)
                {
                    pushub.SendError(revAuthToken);
                }
                return(revAuthToken);
            };
        }
示例#2
0
 /// <summary>
 /// 启动
 /// </summary>
 public void Start()
 {
     this._isConnection = false;
     this._hub          = StreamingHubClient.Connect <IPushHub, IPushHubReceiver>(RpcClient.Instance.Channel, this);
 }