<commit_before>﻿using System.Web.Http;

namespace SimpleIdentityServer.Api.Controllers.Api
{
    public class UserInfoController : ApiController
    {
        public void Get()
        {
            
        }

        public void Post()
        {
            
        }

        private void ProcessRequest()
        {
            var authorization = Request.Headers.Authorization;
            if (authorization == null)
            {
                // TODO throw the appropriate exception.
            }

            var scheme = authorization.Scheme;
            if (scheme != "Bearer")
            {
                // TODO throw the appropriate exception
            }

            var accessToken = authorization.Parameter;
            if (string.IsNullOrWhiteSpace(accessToken))
            {
                // TODO throw the appropriate exception
            }

            // Check the token
        }
    }
}<commit_msg>The user info endpoint returns the claims<commit_after>﻿using SimpleIdentityServer.Core.Api.UserInfo;
using SimpleIdentityServer.Core.Errors;
using SimpleIdentityServer.Core.Exceptions;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace SimpleIdentityServer.Api.Controllers.Api
{
    public class UserInfoController : ApiController
    {
        private readonly IUserInfoActions _userInfoActions;

        public UserInfoController(IUserInfoActions userInfoActions)
        {
            _userInfoActions = userInfoActions;
        }

        public HttpResponseMessage Get()
        {
            return ProcessRequest();
        }

        public HttpResponseMessage Post()
        {
            return ProcessRequest();
        }

        private HttpResponseMessage ProcessRequest()
        {
            try
            {
                var authorization = Request.Headers.Authorization;
                if (authorization == null)
                {
                    throw new AuthorizationException(ErrorCodes.InvalidToken, string.Empty);
                }

                var scheme = authorization.Scheme;
                if (scheme != "Bearer")
                {
                    throw new AuthorizationException(ErrorCodes.InvalidToken, string.Empty);
                }

                var accessToken = authorization.Parameter;
                if (string.IsNullOrWhiteSpace(accessToken))
                {
                    throw new AuthorizationException(ErrorCodes.InvalidToken, string.Empty);
                }
                
                var result = _userInfoActions.GetUserInformation(accessToken);
                return Request.CreateResponse(HttpStatusCode.OK, result);
            }
            catch (AuthorizationException authorizationException)
            {
                var response = Request.CreateResponse(HttpStatusCode.Unauthorized);
                // TODO : add the code & description into the WWW-Authenticate response header.
                return response;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.06697767410863045, 'fraction_numerical': 0.0, 'mean_word_length': 1.576824034334764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6443065', 'n_tokens_mistral': 684, 'n_tokens_neox': 653, 'n_words': 152}