public async Task <GrantedToken> GenerateTokenAsync(IEnumerable <string> audiences, IEnumerable <TicketLine> ticketLines, string scope, string issuerName)
        {
            if (audiences == null)
            {
                throw new ArgumentNullException(nameof(audiences));
            }

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

            if (string.IsNullOrWhiteSpace(scope))
            {
                throw new ArgumentNullException(nameof(scope));
            }

            var expiresIn = await _configurationService.GetRptLifeTime().ConfigureAwait(false);                                      // 1. Retrieve the expiration time of the granted token.

            var jwsPayload = await _jwtGenerator.GenerateAccessToken(audiences, scope.Split(' '), issuerName).ConfigureAwait(false); // 2. Construct the JWT token (client).

            var jArr = new JArray();

            foreach (var ticketLine in ticketLines)
            {
                var jObj = new JObject();
                jObj.Add(Constants.RptClaims.ResourceSetId, ticketLine.ResourceSetId);
                jObj.Add(Constants.RptClaims.Scopes, string.Join(" ", ticketLine.Scopes));
                jArr.Add(jObj);
            }

            jwsPayload.Add(Constants.RptClaims.Ticket, jArr);
            var clientId    = audiences.First();
            var accessToken = await _clientHelper.GenerateIdTokenAsync(clientId, jwsPayload).ConfigureAwait(false);

            var refreshTokenId = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()); // 3. Construct the refresh token.

            return(new GrantedToken
            {
                AccessToken = accessToken,
                RefreshToken = Convert.ToBase64String(refreshTokenId),
                ExpiresIn = expiresIn,
                TokenType = SimpleIdServer.Core.Constants.StandardTokenTypes.Bearer,
                CreateDateTime = DateTime.UtcNow,
                Scope = scope,
                ClientId = clientId
            });
        }