<commit_before>require_dependency "roper/application_controller"

module Roper
  class AuthorizationController < ApplicationController

    before_action :validate_logged_in
    before_action :validate_parameters

    # GET /authorize
    # https://tools.ietf.org/html/rfc6749#section-3.1
    def authorize
      @response_type = params[:response_type]
      render :json => create_error("invalid_request", "response_type is required", nil, @state), :status => 400 and return if !@response_type

      case @response_type
      when 'code'
        # https://tools.ietf.org/html/rfc6749#section-4.1
        process_authorization_code_grant
      when 'token'
        # https://tools.ietf.org/html/rfc6749#section-4.2
        process_implicit_grant
      else
        render :json => create_error("unsupported_response_type", nil, nil, @state), :status => 400 and return
      end
    end

    def approve_authorization
      auth_code_repo = Roper::Repository.for(:authorization_code)
      @authorization_code = auth_code_repo.new(:client_id => @client_id,
                                               :redirect_uri => @request_redirect_uri,
                                               :expires_at => (DateTime.now + 5.minutes))
      auth_code_repo.save(@authorization_code)
      augmented_redirect_uri = "#{params[:redirect_uri]}?code=#{@authorization_code.code}"
      augmented_redirect_uri << "&state=#{params[:state]}" if @state && !@state.blank?
      redirect_to augmented_redirect_uri
    end

    def deny_authorization<commit_msg>Use now correctly when generating authorization code expiration times<commit_after>require_dependency "roper/application_controller"

module Roper
  class AuthorizationController < ApplicationController

    before_action :validate_logged_in
    before_action :validate_parameters

    # GET /authorize
    # https://tools.ietf.org/html/rfc6749#section-3.1
    def authorize
      @response_type = params[:response_type]
      render :json => create_error("invalid_request", "response_type is required", nil, @state), :status => 400 and return if !@response_type

      case @response_type
      when 'code'
        # https://tools.ietf.org/html/rfc6749#section-4.1
        process_authorization_code_grant
      when 'token'
        # https://tools.ietf.org/html/rfc6749#section-4.2
        process_implicit_grant
      else
        render :json => create_error("unsupported_response_type", nil, nil, @state), :status => 400 and return
      end
    end

    def approve_authorization
      auth_code_repo = Roper::Repository.for(:authorization_code)
      @authorization_code = auth_code_repo.new(:client_id => @client_id,
                                               :redirect_uri => @request_redirect_uri,
                                               :expires_at => 5.minutes.from_now)
      auth_code_repo.save(@authorization_code)
      augmented_redirect_uri = "#{params[:redirect_uri]}?code=#{@authorization_code.code}"
      augmented_redirect_uri << "&state=#{params[:state]}" if @state && !@state.blank?
      redirect_to augmented_redirect_uri
    end

    def deny_authorization
{'fraction_non_alphanumeric': 0.09898154042011457, 'fraction_numerical': 0.015913430935709738, 'mean_word_length': 3.0243277848911654, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4759965', 'n_tokens_mistral': 936, 'n_tokens_neox': 883, 'n_words': 166}