Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //--------------------------------------------------------------------------------------------------------------------
        public string pairGetTokens(string redirectUri)
        {
            var req = new PairingNodeGetTokensRequest()
            {
                uuid = this.conf.uuid,
                name = this.conf.Name,
                image = this.conf.Image,
                description = this.conf.Description,
                pathcss = this.conf.Pathcss,
                PairingCompletionInstructions = this.conf.Pairing_CompletionInstructions,
                NoUUIDAuthentication = this.conf.Pairing_NoUUIDAuthentication,
                RedirectUri = redirectUri,
            };
            var uri = this.pairingPostUrl + "/" + NodePairingConstants.s_GetTokensRequest;
            PairingServerTokensResponse resp = (PairingServerTokensResponse)jsonPost(uri, req, typeof(PairingServerTokensResponse));
            if (resp != null)
            {
                this.token1 = resp.token1;
                this.token2 = resp.token2;
                if (this.token1 != null && this.token2 != null)
                {
                    pairingState = PairingStates.TokensSentToNode;
                    return this.token2;
                }
            }
            return null;
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //--------------------------------------------------------------------------------------------------------------------
        public string pairGetTokens(string redirectUri)
        {
            var req = new PairingNodeGetTokensRequest()
            {
                uuid        = this.conf.uuid,
                name        = this.conf.Name,
                image       = this.conf.Image,
                description = this.conf.Description,
                pathcss     = this.conf.Pathcss,
                PairingCompletionInstructions = this.conf.Pairing_CompletionInstructions,
                NoUUIDAuthentication          = this.conf.Pairing_NoUUIDAuthentication,
                RedirectUri = redirectUri,
            };
            var uri = this.pairingPostUrl + "/" + NodePairingConstants.s_GetTokensRequest;
            PairingServerTokensResponse resp = (PairingServerTokensResponse)jsonPost(uri, req, typeof(PairingServerTokensResponse));

            if (resp != null)
            {
                this.token1 = resp.token1;
                this.token2 = resp.token2;
                if (this.token1 != null && this.token2 != null)
                {
                    pairingState = PairingStates.TokensSentToNode;
                    return(this.token2);
                }
            }
            return(null);
        }
Esempio n. 3
0
        //--------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Constructor
        //--------------------------------------------------------------------------------------------------------------------
        public NodePairingBackend(string frontendUrl, NodeConfig conf, OnPairedDelegate callback, OnPairingFailedDelegate onPairingFailedCB)
        {
            this.frontendUrl = frontendUrl;
            this.pairingPostUrl = frontendUrl + "/" + NodePairingConstants.PairingRootURI + "/" + PlegmaAPI.APIVersion;
            this.conf = conf;
            pairingState = PairingStates.Initial;
            this.onPaired += callback;
            this.onPairingFailed += onPairingFailedCB;
        }
Esempio n. 4
0
        //--------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Constructor
        //--------------------------------------------------------------------------------------------------------------------
        public NodePairingBackend(string frontendUrl, NodeConfig conf, OnPairedDelegate callback, OnPairingFailedDelegate onPairingFailedCB)
        {
            this.frontendUrl      = frontendUrl;
            this.pairingPostUrl   = frontendUrl + "/" + NodePairingConstants.PairingRootURI + "/" + PlegmaAPI.APIVersion;
            this.conf             = conf;
            pairingState          = PairingStates.Initial;
            this.onPaired        += callback;
            this.onPairingFailed += onPairingFailedCB;
        }
Esempio n. 5
0
        //--------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Functions
        //--------------------------------------------------------------------------------------------------------------------
        public string pairGetTokens(string redirectUri)
        {
            var req = new PairingNodeGetTokensRequest()
            {
                uuid        = this.conf.uuid,
                name        = this.conf.Name,
                image       = this.conf.Image,
                description = this.conf.Description,
                pathcss     = this.conf.Pathcss,
                PairingCompletionInstructions = this.conf.Pairing_CompletionInstructions,
                NoUUIDAuthentication          = this.conf.Pairing_NoUUIDAuthentication,
                RedirectUri = redirectUri,
            };

            try
            {
                var response = Yodiwo.Tools.Http.RequestPost(this.pairingPostUrl + "/" + NodePairingConstants.s_GetTokensRequest,
                                                             req.ToJSON(),
                                                             HttpRequestDataFormat.Json,
                                                             null);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    onPairingFailed("HTTP Request for tokens failed with " + response.StatusCode);
                    return(null);
                }
                if (string.IsNullOrWhiteSpace(response.ResponseBodyText))
                {
                    onPairingFailed("HTTP Request for tokens returned empty body");
                    return(null);
                }
                var resp = response.ResponseBodyText.FromJSON <PairingServerTokensResponse>();
                if (resp != null)
                {
                    this.token1 = resp.token1;
                    this.token2 = resp.token2;
                    if (this.token1 != null && this.token2 != null)
                    {
                        pairingState = PairingStates.TokensSentToNode;
                        return(this.token2);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugEx.TraceErrorException(ex);
            }
            return(null);
        }