public IActionResult Token([Required] JwtRequest request)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(Forbid());
            }

            try
            {
                var player = _playerService.CreatePlayer(request.PlayerName);
                var jwt    = _jwtService.CreateJwt(player.Id);

                return(Ok(new JwtResponse()
                {
                    Token = jwt,
                    PlayerId = player.Id,
                    PlayerName = player.Name
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Ошибка выдачи токена");
                return(InternalServerError());
            }
        }
        public IActionResult Authenticate(JwtRequest jwtRequest)
        {
            var response = repo.Authenticate(jwtRequest);

            if (response == null)
            {
                return(BadRequest(new { message = "Invalid credentials" }));
            }

            return(Ok(response));
        }
        public async Task <IActionResult> Jwt([FromBody] JwtRequest jwtrq)
        {
            var response = await _busClient.RequestAsync <LoginRequest, LoginResponse>(new LoginRequest
            {
                IdToken = jwtrq.idtoken
            });

            _logger.LogInformation(response.Success
                ? $"Successfully generated JWT '{response.Response}' for GoogleTokenId '{jwtrq.idtoken?.Substring(0, 8)}...'"
                : $"JWT could not be generated for GoogleTokenId '{jwtrq.idtoken?.Substring(0, 8)}...'");

            return(Ok(JsonConvert.SerializeObject(response)));
        }
        public JwtResponse Authenticate(JwtRequest model)
        {
            var user = context.Users.FirstOrDefault(u => u.Username == model.Username && u.Password == model.Password);

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var token = generateJwtToken(user);

            return(new JwtResponse(user, token));
        }
Example #5
0
        public IActionResult CreateToken(JwtRequest login)
        {
            IActionResult response = Unauthorized();

            var loginResult = _userRegistrationService.ValidateUser(_userSettings.UsernamesEnabled ? login.username : login.username, login.password);

            if (loginResult == UserLoginResults.Successful)
            {
                var user = _userService.GetUserByUsername(login.username);

                var tokenString = Jwt.GenerateToken(user);
                response = Ok(new { token = tokenString });
            }

            return(response);
        }
Example #6
0
        public virtual void ProcessRequest(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            //Read Json Masked Wallet Response Jwt
            StreamReader streamReader = new StreamReader(request.InputStream);

            String input;
            String json = "";

            while ((input = streamReader.ReadLine()) != null)
            {
                Console.WriteLine(input);
                json += input;
            }

            Request req = JsonConvert.DeserializeObject <Request> (json);

            //Convert Masked Wallet Response Jwt to Masked Wallet Response object
            String      jsonResponse = JsonWebToken.Decode(req.jwt, Config.getMerchantSecret(), false);
            JwtResponse jwtResponse  = JsonConvert.DeserializeObject <JwtResponse> (jsonResponse);

            //Create Full Wallet Body
            WalletBody fwb = new WalletBody.FullWalletBuilder()
                             .GoogleTransactionId(jwtResponse.response.googleTransactionId)
                             .ClientId(Config.getOauthClientId())
                             .MerchantName(Config.getMerchantName())
                             .Origin(Config.getOrigin(request))
                             .Cart(req.cart)
                             .Build();

            //Create Full Wallet request object
            JwtRequest fwr = new JwtRequest(JwtRequest.FULL_WALLET, Config.getMerchantId(), fwb);

            //Set the expiration time - not necessary but a useful example
            fwr.exp = Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds) + 60000L;

            //Convert the JwtRequest object to a string
            String mwrJwt = JsonWebToken.Encode(fwr, Config.getMerchantSecret(), JwtHashAlgorithm.HS256);

            response.Write(mwrJwt);
        }
Example #7
0
        public virtual void ProcessRequest(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            //Read Json Masked Wallet Response Jwt
            StreamReader streamReader = new StreamReader(request.InputStream);

            String input;
            String json = "";

            while ((input = streamReader.ReadLine()) != null)
            {
                Console.WriteLine(input);
                json += input;
            }

            //Convert Full Wallet Response Jwt to Full Wallet Response object
            Request     req          = JsonConvert.DeserializeObject <Request> (json);
            String      jsonResponse = JsonWebToken.Decode(req.jwt, Config.getMerchantSecret(), false);
            JwtResponse jwtResponse  = JsonConvert.DeserializeObject <JwtResponse> (jsonResponse);

            //Create Transaction Status Notification body
            WalletBody tsb = new WalletBody.TransactionStatusNotificationBuilder()
                             .GoogleTransactionId(jwtResponse.response.googleTransactionId)
                             .ClientId(Config.getOauthClientId())
                             .MerchantName(Config.getMerchantName())
                             .Origin(Config.getOrigin(request))
                             .Status(WalletBody.Status.SUCCESS)
                             .Build();

            //Create Transaction Status Notification object
            JwtRequest tsn = new JwtRequest(JwtRequest.FULL_WALLET, Config.getMerchantId(), tsb);

            tsn.exp = Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds) + 60000L;

            //Convert the JwtRequest object to a string
            String mwrJwt = JsonWebToken.Encode(tsn, Config.getMerchantSecret(), JwtHashAlgorithm.HS256);

            response.Write(mwrJwt);
        }
        public virtual void ProcessRequest(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            //Read the Json defining total price and currency
            StreamReader streamReader = new StreamReader(request.InputStream);

            String input;
            String json = "";

            while ((input = streamReader.ReadLine()) != null)
            {
                Console.WriteLine(input);
                json += input;
            }
            Request req = JsonConvert.DeserializeObject <Request> (json);

            //Create a Masked Wallet body
            WalletBody mwb = new WalletBody.MaskedWalletBuilder()
                             .ClientId(Config.getOauthClientId())
                             .MerchantName(Config.getMerchantName())
                             .Origin(Config.getOrigin(request))
                             .PhoneNumberRequired(true)
                             .Pay(new Pay(req.estimatedTotalPrice, req.currencyCode))
                             .Ship(new Ship())
                             .Build();

            //Create the request object
            JwtRequest mwr = new JwtRequest(JwtRequest.MASKED_WALLET, Config.getMerchantId(), mwb);

            //Set the expiration time - not necessary but a useful example
            mwr.exp = Convert.ToInt64(DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds) + 60000L;

            //Convert the JwtRequest object to a string
            String mwrJwt = JsonWebToken.Encode(mwr, Config.getMerchantSecret(), JwtHashAlgorithm.HS256);

            //Respond with the Jwt
            response.Write(mwrJwt);
        }