public LogGenerator(ITokenExtractor extractor, ITokenTransformer transformer, ISink sink, ILogger <LogGenerator> logger) { this.extractor = extractor; this.transformer = transformer; this.sink = sink; this.logger = logger; this.random = new Random(); this.randomLock = new Object(); }
public GenerateShortTokenCommand(ITokenExtractor refreshTokenExtracter, ICachedRepo <string> revokedTokenRepo, ISymmetricKeyProvider symmetricKeyProvider, ISecretGenerator tokenIdGenerator, JwtConfig shortTokenConfig, ILogger logger) { _refreshTokenExtracter = refreshTokenExtracter; _revokedTokenRepo = revokedTokenRepo; _symmetricKeyProvider = symmetricKeyProvider; _tokenIdGenerator = tokenIdGenerator; _shortTokenConfig = shortTokenConfig; _logger = logger; }
public async Task <IActionResult> Renew([FromBody] RTokenRenewModel renewModel, [FromServices] IRequestClient <UserClaimsMQRequest> userClaimsReqClient, [FromServices] IGenerateRefreshTokenCommand generateRefreshTokenCommand, [FromServices] ITokenExtractor refreshTokenExtractor) { string correlationId = null; try { if (renewModel == null) { return(BadRequest(ValueResponse <TokenResult> .GeneralError("Something went wrong"))); } correlationId = Guid.NewGuid().ToString("N"); //Old token verification and accountId retrieval goes here if (!refreshTokenExtractor.TryExractToken(renewModel.OldRToken, out List <Claim> oldClaims)) { return(BadRequest(ValueResponse <TokenResult> .GeneralError("Something went wrong"))); } string accountId = oldClaims.Single(x => x.Type == "Account").Value; //Problem with dates DateTime expiredOld = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Unspecified).AddSeconds((long.Parse(oldClaims.Single(x => x.Type == "exp").Value))); //Get user and generate user claims Response <UserClaimsMQResponse> claimsResp = await userClaimsReqClient.GetResponse <UserClaimsMQResponse>(new UserClaimsMQRequest() { CorrelationId = correlationId, AccountId = accountId, ClaimsConsumers = renewModel.ClaimsConsumers }); if (claimsResp.Message.OpSuccess != true) { throw new Exception("Error with userClaimsReqClient request"); } //Generate refresh token var newClaims = claimsResp.Message.GetClaims(); var req = ControllerContext.HttpContext.Request; TokenAdditionalData additionalData = new TokenAdditionalData() { DeviceInfo = "Device info", RequesterIPv4 = "ipv4", RequesterIPv6 = "ipv6" }; TokenResult rTokenResult = await generateRefreshTokenCommand.Execute(accountId, newClaims, additionalData, expiredOld); return(Created("", rTokenResult)); } catch (Exception ex) { //Log error _logger.LogError("RefreshTokenController.Renew", "Exception was thrown", new { CorrelationId = correlationId, TokenRenewModel = renewModel, Exception = ex }); return(BadRequest(ValueResponse <TokenResult> .GeneralError("Something went wrong"))); } }