Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task InvokeAsync(HttpContext context)
- {
- var authInfo = context.Request.Headers.GetCommaSeparatedValues("Authorization");
- string userName = null;
- string password = null;
- if (authInfo.Length > 0)
- {
- var loginInfo = authInfo[0].Split(" ");
- if (loginInfo.Length == 2)
- {
- var base64String = loginInfo[1];
- var decodedByteData = System.Convert.FromBase64String(base64String);
- var decodedInfo = System.Text.Encoding.UTF8.GetString(decodedByteData).Split(":");
- userName = decodedInfo[0];
- password = decodedInfo[1];
- }
- }
- if (userName == "qwe" && password == "123")
- {
- await _next.Invoke(context);
- }
- else
- {
- context.Response.StatusCode = 403;
- await context.Response.WriteAsync($"Not authorized");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement