CreatePrincipal() 공개 정적인 메소드

public static CreatePrincipal ( string username, string octopusApiKey ) : ClaimsPrincipal
username string
octopusApiKey string
리턴 System.Security.Claims.ClaimsPrincipal
예제 #1
0
        public async Task Invoke(HttpContext httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            string apiKey;

            if (TryGetApiKey(httpContext.Request, out apiKey))
            {
                var userName = await _octopusAuthenticationProxy.ValidateApiKey(apiKey);

                if (!string.IsNullOrEmpty(userName))
                {
                    var principal = ClaimsPrincipalHelpers.CreatePrincipal(userName, apiKey);

                    httpContext.User = principal;
                }
            }

            await _next.Invoke(httpContext);
        }
예제 #2
0
        public Task Invoke(HttpContext httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            string apiKey;

            if (TryGetApiKey(httpContext.Request, out apiKey))
            {
                string userName;
                if (_octopusAuthenticationProxy.ValidateApiKey(apiKey, out userName))
                {
                    var principal = ClaimsPrincipalHelpers.CreatePrincipal(userName, apiKey);

                    httpContext.User        = principal;
                    Thread.CurrentPrincipal = principal;
                }
            }

            return(_next.Invoke(httpContext));
        }