<commit_before># frozen_string_literal: true

# DMPRoamap Notes:
# -----------------------------------------------------------------------
# This initializer defines the OAuth2 security settings for DMPRoadmap. It allows external
# systems to access public data, and allows Users to authorize external systems to access
# their data (e.g. private plans)
#
# All of the default Doorkeeper settings have been left commented out below in the event that
# you would like to further modify the behavior.
#
# For an overview of this OAuth2 implementation, please see the wiki article:
#   https://github.com/DMPRoadmap/roadmap/wiki/API-Documentation-V2

# rubocop:disable Metrics/BlockLength
Doorkeeper.configure do
  # Change the ORM that doorkeeper will use (requires ORM extensions installed).
  # Check the list of supported ORMs here: https://github.com/doorkeeper-gem/doorkeeper#orms
  orm :active_record

  # DMPRoadmap Notes:
  # -----------------------------------------------------------------------
  # This block will be called as part of the :authentication_code grant flow to check whether
  # the resource owner is authenticated or not.
  # If not, they will be redirected to the Doorkeeper version of the oauth_authorization_path which
  # is a paired down version of the sign in form found on the home page. It renders the
  # app/views/doorkeeper/authorizations/new.html.erb using the doorkeeper specific
  # layout located at: app/views/layouts/doorkeeper/application.html.erb
  #
  resource_owner_authenticator do
    # current_user

Rails.logger.warn "PARAMS: #{params.inspect}"

    # The user must be signed_in in to provide authorization for the ApiClient
    # if they are not, send them to the oauth sign in page
    oauth_path = oauth_authorization_path(client_id: params['client_id'],
      redirect_uri: params['redirect_uri'],
      state: params['state'],
      response_type: params['response_type'],
      scope: params['scope'],
      code_challenge: params['code_challenge'],
      code_challenge_method: params['code_challenge_method'])
    }
    session['oauth-referer'] = ApplicationService.encrypt(payload: { client_id: params['client_id'],
                                                                     path: oauth_path })

    current_user || render('doorkeeper/authorizations/new', layout: 'doorkeeper/application')

    #               render('/users/oauth_signin',
    #                        layout: 'doorkeeper/application',
    #                        locals: { client: ApiClient.find_by(uid: params['client_id']) })
  end

  # If you didn't skip applications controller from Doorkeeper routes in your application routes.rb
  # file then you need to declare this block in order to restrict access to the web interface for
  # adding oauth authorized applications. In other case it will return 403 Forbidden response
  # every time somebody will try to access the admin web interface.
  admin_authenticator do
    #   # Put your admin authentication logic here.
    #   # Example implementation:
    #
    if current_user
      head :forbidden unless current_user.can_org_admin?
    else
      redirect_to sign_in_url
    end<commit_msg>moved doorkeeper views out of branded dir into main views dir<commit_after># frozen_string_literal: true

# DMPRoamap Notes:
# -----------------------------------------------------------------------
# This initializer defines the OAuth2 security settings for DMPRoadmap. It allows external
# systems to access public data, and allows Users to authorize external systems to access
# their data (e.g. private plans)
#
# All of the default Doorkeeper settings have been left commented out below in the event that
# you would like to further modify the behavior.
#
# For an overview of this OAuth2 implementation, please see the wiki article:
#   https://github.com/DMPRoadmap/roadmap/wiki/API-Documentation-V2

# rubocop:disable Metrics/BlockLength
Doorkeeper.configure do
  # Change the ORM that doorkeeper will use (requires ORM extensions installed).
  # Check the list of supported ORMs here: https://github.com/doorkeeper-gem/doorkeeper#orms
  orm :active_record

  # DMPRoadmap Notes:
  # -----------------------------------------------------------------------
  # This block will be called as part of the :authentication_code grant flow to check whether
  # the resource owner is authenticated or not.
  # If not, they will be redirected to the Doorkeeper version of the oauth_authorization_path which
  # is a paired down version of the sign in form found on the home page. It renders the
  # app/views/doorkeeper/authorizations/new.html.erb using the doorkeeper specific
  # layout located at: app/views/layouts/doorkeeper/application.html.erb
  #
  resource_owner_authenticator do
    # current_user

Rails.logger.warn "PARAMS: #{params.inspect}"

    # The user must be signed_in in to provide authorization for the ApiClient
    # if they are not, send them to the oauth sign in page
    oauth_path = oauth_authorization_path(client_id: params['client_id'],
      redirect_uri: params['redirect_uri'],
      state: params['state'],
      response_type: params['response_type'],
      scope: params['scope'],
      code_challenge: params['code_challenge'],
      code_challenge_method: params['code_challenge_method'])

    session['oauth-referer'] = ApplicationService.encrypt(payload: { client_id: params['client_id'],
                                                                     path: oauth_path })

    current_user || render('doorkeeper/authorizations/new', layout: 'doorkeeper/application')

    #               render('/users/oauth_signin',
    #                        layout: 'doorkeeper/application',
    #                        locals: { client: ApiClient.find_by(uid: params['client_id']) })
  end

  # If you didn't skip applications controller from Doorkeeper routes in your application routes.rb
  # file then you need to declare this block in order to restrict access to the web interface for
  # adding oauth authorized applications. In other case it will return 403 Forbidden response
  # every time somebody will try to access the admin web interface.
  admin_authenticator do
    #   # Put your admin authentication logic here.
    #   # Example implementation:
    #
    if current_user
      head :forbidden unless current_user.can_org_admin?
    else
      redirect_to sign_in_url
    end
{'fraction_non_alphanumeric': 0.11180414782473101, 'fraction_numerical': 0.0018711991267737408, 'mean_word_length': 2.820131030375223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7128860', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1619, 'n_words': 611}