public async Task <ProductsForPlayerResponse> GetProductsForPlayerAsync(ProductsForPlayerRequest request, string lobbyToken)
        {
            var lobbyId  = _tokenProvider.Decrypt(lobbyToken);
            var playerId = _tokenProvider.Decrypt(request.authtoken);

            var playerInfo = await GetLobbyPlayerAsync(playerId);

            var productsInfo = await GetProductsDataAsync(lobbyId, playerInfo);

            return(new ProductsForPlayerResponse()
            {
                products = productsInfo,
                player = playerInfo
            });
        }
Exemplo n.º 2
0
        public void Can_Decrypt_Token()
        {
            var            playerId  = Guid.NewGuid();
            var            encrypted = playerId.ToString();
            ITokenProvider tp        = Create <TokenProvider, ITokenProvider>();

            var decrypted = tp.Decrypt(encrypted);

            decrypted.Should().Be(playerId);
        }
        public static Guid GetIdFromAuthToken(this HttpActionContext context, ITokenProvider tokenProvider)
        {
            IEnumerable <string> values;

            if (context.Request.Headers.TryGetValues("Authorization", out values))
            {
                var authorization = values.FirstOrDefault();
                if (authorization != null && authorization.StartsWith("Bearer", true, null))
                {
                    var token = authorization.Substring(6).Trim();
                    return(tokenProvider.Decrypt(token));
                }
            }
            else
            {
                var req = context.ActionArguments.Values.OfType <IStringTokenHolder>().FirstOrDefault();
                if (req != null)
                {
                    return(tokenProvider.Decrypt(req.token));
                }
            }

            throw new InvalidTokenException("Missing Authorization Bearer Header");
        }