Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new authorization request
        /// </summary>
        /// <param name="credentials">PagSeguro credentials. Required</param>
        /// <param name="authorizationRequest">PagSeguro AuthorizationRequest</param>
        /// <param name="onlyAuthorizationCode"></param>
        /// <returns></returns>
        public static string CreateAuthorizationRequest(Credentials credentials, AuthorizationRequest authorizationRequest, bool onlyAuthorizationCode)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "AuthorizationService.CreateAuthorizationRequest() - begin"));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection(
                           PagSeguroConfiguration.AuthorizarionRequestUri.AbsoluteUri, buildAuthorizationRequestUrl(credentials, authorizationRequest)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        AuthorizationResponse authorization = new AuthorizationResponse();
                        AuthorizationSerializer.Read(reader, authorization);

                        if (onlyAuthorizationCode)
                        {
                            return(authorization.Code);
                        }
                        else
                        {
                            return(BuildAuthorizationURL(authorization.Code));
                        }
                    }
                }
            }
            catch (WebException pse)
            {
                throw pse;
            }
            catch (PagSeguroServiceException pse)
            {
                throw pse;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new authorization request
        /// </summary>
        /// <param name="credentials">PagSeguro credentials. Required</param>
        /// <param name="authorizationRequest">PagSeguro AuthorizationRequest</param>
        /// <param name="onlyAuthorizationCode"></param>
        /// <returns></returns>
        public static string CreateAuthorizationRequest(Credentials credentials, AuthorizationRequest authorizationRequest, bool onlyAuthorizationCode)
        {
            PagSeguroTrace.Info(string.Format(CultureInfo.InvariantCulture, "AuthorizationService.CreateAuthorizationRequest() - begin"));

            try
            {
                using (var response = HttpUrlConnectionUtil.GetHttpPostConnection(
                           PagSeguroUris.GetAuthorizarionRequestUri(credentials).AbsoluteUri, BuildAuthorizationRequestUrl(credentials, authorizationRequest)))
                {
                    using (var reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        var authorization = new AuthorizationResponse();
                        AuthorizationSerializer.Read(reader, authorization);

                        return(onlyAuthorizationCode ? authorization.Code : BuildAuthorizationUrl(credentials, authorization.Code));
                    }
                }
            }
            catch (WebException pse)
            {
                throw pse;
            }
            catch (PagSeguroServiceException pse)
            {
                throw pse;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Metoda autoryzująca połączenie klienckie. Po poprawnej autoryzacji, łączy z odpowiednim Lobby
        /// </summary>
        /// <param name="conn">Połączenie klienta</param>
        /// <param name="requestData">Dane zapytania (dane autoryzacyjne)</param>
        /// <returns>Informacja, czy autoryzacja zakończyła się powodzeniem</returns>
        protected override bool AuthorizeConnection(ClientConnection conn, JObject requestData)
        {
            var serializer = new AuthorizationSerializer(requestData);

            try {
                serializer.Validate();

                conn.Session.Set("username", serializer.Login);
                LobbiesManager.JoinLobby(conn, serializer.LobbyId, serializer.LobbyPassword);
            } catch (Exception) {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public void Authorize()
        {
            var authData = new AuthorizationSerializer()
            {
                Login         = Username,
                LobbyPassword = "",
                LobbyId       = "DEFAULT"
            };
            var authRequest = ClientSocket.SendRequest(authData.GetApiObject());

            while (authRequest.RequestState != RequestState.RESPONSE_RECEIVED)
            {
                ClientSocket.UpdateCommunication();
            }
            Console.WriteLine("Authorized " + Username);
        }