コード例 #1
0
        bool AuthorizeRequest(HttpRequestMessage request)
        {
            if (request.Headers.Contains(TokenAuthorizeAttribute.Header))
            {
                var token = request.GetAuthorizationToken();

                var session = _sessionService.Authenticate(token);
                if (session != null)
                {
                    var identity  = new GenericIdentity(session.User.Name);
                    var principle = new GenericPrincipal(identity, new string[] {});
                    Thread.CurrentPrincipal = principle;
                    if (HttpContext.Current != null)
                    {
                        HttpContext.Current.User = principle;
                    }

                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        public async Task <ActionResult <SessionResponseViewModel> > logIn([FromBody] SessionRequestViewModel user)
        {
            var session = await _user.Authenticate(user);

            return(Ok(session));
        }