private async Task ValidatePayload(
            AuthenticationPayload payload, ApplicationEntity application)
        {
            //Valid request
            if (payload.OldSyncKey == application.NewSyncKey)
            {
                application.OldSyncKey = payload.OldSyncKey;
                application.NewSyncKey = payload.NewSyncKey;

                await mApplicationStore.UpdateState(application.Id, application.OldSyncKey,
                                                    application.NewSyncKey);
            }
            //Handling errors
            else if (payload.OldSyncKey == application.OldSyncKey &&
                     payload.NewSyncKey == application.NewSyncKey)
            {
                throw new ValidationFailedException("Payload invalid - equal to stored payload");
            }
            //Probably compromised private key
            else
            {
                await mApplicationStore.Revoke(application.Id);

                throw new ValidationFailedException("Payload is invalid, application revoked");
            }
        }
Example #2
0
        /// <summary>
        /// Authenticate the client API
        /// </summary>
        /// <param name="apiKey"></param>
        public async Task Authenticate(string apiKey)
        {
            var payload = new AuthenticationPayload()
            {
                ApiKey = apiKey
            };
            var response = await Post <AuthenticationPayload, AuthenticationResponse>("/authentication/token", payload);

            HashKey = response.HashKey;
            SetSessionAlias(response.Token);
        }
Example #3
0
        private static async Task GetAuthenticationToken()
        {
            var httpNew = (HttpWebRequest)WebRequest.Create("https://login.globo.com/api/authentication");

            httpNew.ContentType = "application/json;charset=UTF-8";
            httpNew.UserAgent   =
                "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36";
            httpNew.Method = "POST";

            ServicePointManager.SecurityProtocol =
                SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;


            var payload = new AuthenticationPayload
            {
                payload = new Payload
                {
                    email     = "*****@*****.**",
                    password  = "******",
                    serviceId = 438
                }
            };

            string json = JsonConvert.SerializeObject(payload);

            var client      = new HttpClient();
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");

            var response = await client.PostAsync("https://login.globo.com/api/authentication", httpContent);

            if (response.Content != null)
            {
                var responseContent = await response.Content.ReadAsStringAsync();

                Globals.Token = JsonConvert.DeserializeObject <AuthenticationInfo>(responseContent).glbId;
            }
        }
Example #4
0
 public async Task <AuthenticationResponse> GetAuthenticationResponse(AuthenticationPayload payload)
 {
     return(JsonConvert.DeserializeObject <AuthenticationResponse>(await SendRequest(payload)));
 }
Example #5
0
 public MojangAccountServiceTests()
 {
     validTokenPayload   = fixture.Create <TokenPayload>();
     invalidTokenPayload = fixture.Create <TokenPayload>();
     validAuthPayload    = new AuthenticationPayload(fixture.Create <string>(), fixture.Create <string>(), validTokenPayload.ClientToken);
 }