private void HandleAuthenticateRequestRequestInternal(ISonarAuthPassthroughHttpContext context) { if (context.User != null) { traceSource.TraceEvent(TraceEventType.Information, 0, "Already authenticated"); return; } // This is most efficent. if (context.HasTokenHeader) { traceSource.TraceEvent(TraceEventType.Information, 0, "Found token."); AssignPassThruUser(context); return; } // If we have no agent, or the agent does not match any of our pass thrus string userAgent = context.UserAgent; traceSource.TraceEvent(TraceEventType.Information, 0, $"UserAgent: '{userAgent}'"); if (string.IsNullOrWhiteSpace(userAgent) || this.settings.PassThruUserAgents.Any(userAgent.StartsWith)) { AssignPassThruUser(context); return; } }
private void AssignPassThruUser(ISonarAuthPassthroughHttpContext context) { traceSource.TraceEvent(TraceEventType.Information, 0, "Assigning token user."); context.User = passThruUser; context.SkipAuthorization = true; }
/// <summary> /// Handle an authenticateRequest using the <paramref name="context"/>. /// </summary> /// <param name="context">The context to be used when handling an AuthorizeRequest</param> internal void HandleAuthenticateRequest(ISonarAuthPassthroughHttpContext context) { try { traceSource.TraceEvent(TraceEventType.Start, 0, "START AuthenticateRequest"); HandleAuthenticateRequestRequestInternal(context); } catch (Exception ex) { traceSource.TraceEvent(TraceEventType.Error, 0, $"ERROR AuthenticateRequest: ExceptionData: '{ex}' "); throw; } finally { traceSource.TraceEvent(TraceEventType.Stop, 0, "END AuthenticateRequest"); } }