Ejemplo n.º 1
0
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        //args.purchasedProduct.receipt

        PurchaseReceipt tempReceipt = JsonUtility.FromJson <PurchaseReceipt>(args.purchasedProduct.receipt);

                #if UNITY_ANDROID
        GooglePayload tempGooglelPayload = JsonUtility.FromJson <GooglePayload>(tempReceipt.Payload);
        mStrReceiptJSON = tempGooglelPayload.json;
        GooglePayloadJson tempGooglePayloadJson = JsonUtility.FromJson <GooglePayloadJson>(tempGooglelPayload.json);
        if (tempGooglePayloadJson.developerPayload != null)
        {
            StartCoroutine(PostPayloadValidation(token, tempGooglePayloadJson.developerPayload, ValidSuccessDeveloperPayloadCallback));
        }
        else
        {
            StartCoroutine(PostReceiptValidation(token, mStrReceiptJSON, () => {
                PrintConsole("Receipt is valid");
            }));
        }
                #elif UNITY_IOS
        StartCoroutine(PostReceiptValidation(token, tempReceipt.Payload, () => {
            PrintConsole("Receipt is valid");
        }));
                #endif

        // A consumable product has been purchased by this user.
        // if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal))
        // {
        //     PrintConsole(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
        //     // The consumable item has been successfully purchased, add 100 coins to the player's in-game score.
        //     ScoreManager.score += 100;
        // }
        // // Or ... a non-consumable product has been purchased by this user.
        // else if (String.Equals(args.purchasedProduct.definition.id, kProductIDNonConsumable, StringComparison.Ordinal))
        // {
        //     PrintConsole(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
        //     // TODO: The non-consumable item has been successfully purchased, grant this item to the player.
        // }
        // // Or ... a subscription product has been purchased by this user.
        // else if (String.Equals(args.purchasedProduct.definition.id, kProductIDSubscription, StringComparison.Ordinal))
        // {
        //     PrintConsole(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
        //     // TODO: The subscription item has been successfully purchased, grant this to the player.
        // }
        // // Or ... an unknown product has been purchased by this user. Fill in additional products here....
        // else
        // {
        //     PrintConsole(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
        // }

        // Return a flag indicating whether this product has completely been received, or if the application needs
        // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
        // saving purchased products to the cloud, and when that save is delayed.
        return(PurchaseProcessingResult.Complete);
    }
Ejemplo n.º 2
0
 private IEnumerable <Claim> GenerateClaims(GooglePayload payload)
 {
     return(new List <Claim>
     {
         new Claim(JwtRegisteredClaimNames.Iss, _identityOptions.ApplicationIssuer),
         new Claim(JwtApplicationClaimsNames.DisplayName, payload.DisplayName),
         new Claim(JwtApplicationClaimsNames.Locale, payload.Locale),
         new Claim(JwtApplicationClaimsNames.Picture, payload.Picture),
         new Claim(JwtRegisteredClaimNames.Azp, _identityOptions.ApplicationAudience),
         new Claim(JwtRegisteredClaimNames.GivenName, payload.FirstName),
         new Claim(JwtRegisteredClaimNames.FamilyName, payload.LastName),
         new Claim(JwtRegisteredClaimNames.Email, payload.Email),
         new Claim(JwtRegisteredClaimNames.Sub, payload.UserIdentifier),
         new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
         new Claim(JwtApplicationClaimsNames.GoogleIdToken, payload.GoogleIdToken)
         //new Claim(JwtApplicationClaimsNames.GoogleRefreshToken, payload?.GoogleRefreshToken)
     });
 }
Ejemplo n.º 3
0
        public ApplicationToken GenerateBearerTokenAsync(GooglePayload payload)
        {
            var privateKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_identityOptions.ApplicationSecret));
            var creds      = new SigningCredentials(privateKey, SecurityAlgorithms.HmacSha256);
            var expires    = DateTime.UtcNow.AddSeconds(60 * 60 * 8);

            var token = new JwtSecurityToken(
                issuer: _identityOptions.ApplicationIssuer,
                audience: _identityOptions.ApplicationAudience,
                claims: GenerateClaims(payload),
                expires: expires,
                signingCredentials: creds
                );

            return(new ApplicationToken
            {
                Token = new JwtSecurityTokenHandler().WriteToken(token),
                Expires = expires
            });
        }
Ejemplo n.º 4
0
        public async Task <RespostaCommand> AutenticarComGoogleAsync(string tokenTemporario)
        {
            var resposta = new RespostaCommand();

            try
            {
                var payload = await GoogleJsonWebSignature.ValidateAsync(
                    tokenTemporario, new GoogleJsonWebSignature.ValidationSettings());

                var googlePayload = new GooglePayload(payload.Subject, payload.Email,
                                                      payload.GivenName, payload.FamilyName, payload.JwtId, payload);

                resposta.Dados = googlePayload;
                return(resposta);
            }
            catch
            {
                resposta.ValidationResult.Errors.Add(new FluentValidation.Results.ValidationFailure(
                                                         nameof(AutenticarComGoogleAsync), "Token google inválido"));
                return(resposta);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initialises a new instance of PayloadWrapper
 /// </summary>
 public PayloadWrapper()
 {
     Google = new GooglePayload();
 }