Skip to content

Commit b0bf3b0

Browse files
hftl-kallekirkone
authored andcommitted
Allow unauthenticated access to path defined in options.authendpoint (#5)
1 parent f01a01a commit b0bf3b0

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/KK.AspNetCore.EasyAuthAuthentication/EasyAuthAuthenticationHandler.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
3131
Logger.LogInformation("starting authentication handler for app service authentication");
3232

3333
if (
34-
this.Context.User == null ||
34+
(this.Context.User == null ||
3535
this.Context.User.Identity == null ||
36-
this.Context.User.Identity.IsAuthenticated == false
37-
)
36+
this.Context.User.Identity.IsAuthenticated == false ) && this.Context.Request.Path != "/" + $"{Options.AuthEndpoint}")
3837
{
3938
var cookieContainer = new CookieContainer();
4039
HttpClientHandler handler = createHandler(ref cookieContainer);
@@ -50,7 +49,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
5049
return AuthenticateResult.Fail(ex.Message);
5150
}
5251

53-
//build up identity from json...
52+
// build up identity from json...
5453
AuthenticationTicket ticket = BuildIdentityFromJsonPayload((JObject)payload[0]);
5554

5655
Logger.LogInformation("Set identity to user context object.");
@@ -116,7 +115,7 @@ private HttpRequestMessage CreateAuthRequest(ref CookieContainer cookieContainer
116115
Logger.LogDebug(cookie.Key);
117116
}
118117

119-
//fetch value from endpoint
118+
// fetch value from endpoint
120119
var request = new HttpRequestMessage(HttpMethod.Get, $"{uriString}/{Options.AuthEndpoint}");
121120
foreach (var header in Context.Request.Headers)
122121
{
@@ -125,6 +124,7 @@ private HttpRequestMessage CreateAuthRequest(ref CookieContainer cookieContainer
125124
request.Headers.Add(header.Key, header.Value[0]);
126125
}
127126
}
127+
128128
return request;
129129
}
130130

@@ -158,8 +158,8 @@ private async Task<JArray> getAuthMe(HttpClientHandler handler, HttpRequestMessa
158158
{
159159
throw new JsonSerializationException("Could not retreive json from /me endpoint.");
160160
}
161+
}
161162

162-
};
163163
return payload;
164164
}
165165
}

0 commit comments

Comments
 (0)