<commit_before>﻿using System;
using Nancy.ModelBinding;
using Nancy.OAuth2.Enums;
using Nancy.OAuth2.Models;
using Nancy.OAuth2.Services;
using Nancy.Security;

namespace Nancy.OAuth2.Modules
{
    public class AuthorizeModule : NancyModule
    {
        private readonly IAuthorizationEndpointService _service;
        private readonly IErrorResponseBuilder _errorResponseBuilder;

        public AuthorizeModule(
            IAuthorizationEndpointService service,
            IErrorResponseBuilder errorResponseBuilder)
            : base(OAuth.Configuration.GetFullPath(x => x.AuthorizationRequestRoute))
        {
            _service = service;
            _errorResponseBuilder = errorResponseBuilder;
            this.RequiresAuthentication();

            Get["/", ctx => OAuth.IsEnabled] = _ => Index();
            Post[OAuth.Configuration.AuthorizationAllowRoute, ctx => OAuth.IsEnabled] = _ => Allow();
            Post[OAuth.Configuration.AuthorizationDenyRoute, ctx => OAuth.IsEnabled] = _ => Deny();
        }

        private dynamic Index()
        {
            var request = this.Bind<AuthorizationRequest>();

            var result = _service.ValidateRequest(request, Context);

            if (!result.IsValid)
            {
                return Response.AsErrorResponse(BuildErrorResponse(result.ErrorType, request.State), request.RedirectUrl);
            }

            Session[Context.CurrentUser.UserName] = request;

            var authorizationView = _service.GetAuthorizationView(request, Context);

            return View[authorizationView.Item1, authorizationView.Item2];
        }

        private dynamic Allow()
        {
            var token = _service.GenerateAuthorizationToken(Context);
            var request = Session[Context.CurrentUser.UserName] as AuthorizationRequest;
<commit_msg>Added space between private field setters and the call to RequiresAuthentication.<commit_after>﻿using System;
using Nancy.ModelBinding;
using Nancy.OAuth2.Enums;
using Nancy.OAuth2.Models;
using Nancy.OAuth2.Services;
using Nancy.Security;

namespace Nancy.OAuth2.Modules
{
    public class AuthorizeModule : NancyModule
    {
        private readonly IAuthorizationEndpointService _service;
        private readonly IErrorResponseBuilder _errorResponseBuilder;

        public AuthorizeModule(
            IAuthorizationEndpointService service,
            IErrorResponseBuilder errorResponseBuilder)
            : base(OAuth.Configuration.GetFullPath(x => x.AuthorizationRequestRoute))
        {
            _service = service;
            _errorResponseBuilder = errorResponseBuilder;

            this.RequiresAuthentication();

            Get["/", ctx => OAuth.IsEnabled] = _ => Index();
            Post[OAuth.Configuration.AuthorizationAllowRoute, ctx => OAuth.IsEnabled] = _ => Allow();
            Post[OAuth.Configuration.AuthorizationDenyRoute, ctx => OAuth.IsEnabled] = _ => Deny();
        }

        private dynamic Index()
        {
            var request = this.Bind<AuthorizationRequest>();

            var result = _service.ValidateRequest(request, Context);

            if (!result.IsValid)
            {
                return Response.AsErrorResponse(BuildErrorResponse(result.ErrorType, request.State), request.RedirectUrl);
            }

            Session[Context.CurrentUser.UserName] = request;

            var authorizationView = _service.GetAuthorizationView(request, Context);

            return View[authorizationView.Item1, authorizationView.Item2];
        }

        private dynamic Allow()
        {
            var token = _service.GenerateAuthorizationToken(Context);
            var request = Session[Context.CurrentUser.UserName] as AuthorizationRequest;

{'fraction_non_alphanumeric': 0.08438253415483525, 'fraction_numerical': 0.0032145727297080095, 'mean_word_length': 2.700693756194252, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '4032006', 'n_tokens_mistral': 903, 'n_tokens_neox': 899, 'n_words': 184}