public static bool TryReadCustomAuthorization(
            this MessageReceivedContext context,
            JwtBearerOptions options,
            TetraPakApiAuthConfig authConfig,
            ILogger logger,
            out string authorization)
        {
            using (logger?.BeginScope($"Looking for authorization in header: {authConfig.AuthorizationHeader}"))
            {
                if (!authConfig.IsCustomAuthorizationHeader)
                {
                    logger.Debug("Default authorization header is in use");
                    authorization = null;
                    return(false);
                }

                authorization = context.Request.Headers[authConfig.AuthorizationHeader];
                var isTokenAvailable = !string.IsNullOrWhiteSpace(authorization);
                var isJwtToken       = authorization.TryParseToJwtSecurityToken(out var jwt);

                if (!logger?.IsEnabled(LogLevel.Debug) ?? false)
                {
                    return(isTokenAvailable);
                }

                logger.Debug($"Received message: {context.Request.Path.Value}");
                if (!isTokenAvailable)
                {
                    logger.Debug("No authorization found");
                    return(false);
                }

                if (isJwtToken)
                {
                    logger.Debug($"Received JWT: \n{jwt.ToDebugString()}");
                    logger.Debug($"Environment: {authConfig.Environment}");
                    logger.Debug($"Discovery document URL: {options.MetadataAddress}");
                    return(true);
                }

                logger.Debug($"Received token: \n{authorization}");
                return(true);
            }
        }
 public TetraPakTokenExchangeService(TetraPakApiAuthConfig authConfig, ILogger <TetraPakTokenExchangeService> logger)
 {
     _authConfig = authConfig ?? throw new ArgumentNullException(nameof(authConfig));
     Logger      = logger;
 }
 public SidecarJwBearerAssertionOptions(TetraPakApiAuthConfig authConfig)
 {
     AuthConfig = authConfig;
 }
Example #4
0
 public TetraPakClientCredentialsService(TetraPakApiAuthConfig authConfig)
 {
     _authConfig = authConfig;
 }