<commit_before>require 'jwt'

module OAuth2
  module Strategy
    # The Client Assertion Strategy
    #
    # @see https://tools.ietf.org/html/rfc7523
    #
    # Sample usage:
    #   client = OAuth2::Client.new(client_id, client_secret,
    #                               :site => 'http://localhost:8080',
    #                               :auth_scheme => :request_body)
    #
    #   claimset = {
    #     :iss => "http://localhost:3001",
    #     :aud => "http://localhost:8080/oauth2/token"
    #     :sub => "<EMAIL>",
    #     :exp => Time.now.utc.to_i + 3600
    #   }
    #
    #   access = client.assertion.get_token(claimset, :algorithm => 'HS256', :key => 'secret_key')
    #   access.token                 # actual access_token string
    #   access.get("/api/stuff")     # making api calls with access token in header
    #
    class Assertion < Base
      # Not used for this strategy
      #
      # @raise [NotImplementedError]
      def authorize_url
        raise(NotImplementedError, 'The authorization endpoint is not used in this strategy')
      end

      # Retrieve an access token given the specified client.
      #
      # @param [Hash] claims the hash representation of the claims that should be encoded as a JWT (JSON Web Token)
      #
      # For reading on JWT and claim keys:
      #   @see https://github.com/jwt/ruby-jwt
      #   @see https://tools.ietf.org/html/rfc7519#section-4.1
      #   @see https://tools.ietf.org/html/rfc7523#section-3
      #   @see https://www.iana.org/assignments/jwt/jwt.xhtml
      #
      # There are many possible claim keys, and applications may ask for their own custom keys.
      # Some typically required ones:
      #   :iss (issuer)<commit_msg>Better comment example for clarity of new hash args<commit_after>require 'jwt'

module OAuth2
  module Strategy
    # The Client Assertion Strategy
    #
    # @see https://tools.ietf.org/html/rfc7523
    #
    # Sample usage:
    #   client = OAuth2::Client.new(client_id, client_secret,
    #                               :site => 'http://localhost:8080',
    #                               :auth_scheme => :request_body)
    #
    #   claimset = {
    #     :iss => "http://localhost:3001",
    #     :aud => "http://localhost:8080/oauth2/token"
    #     :sub => "<EMAIL>",
    #     :exp => Time.now.utc.to_i + 3600,
    #   }
    #
    #   encoding = {
    #     :algorithm => 'HS256',
    #     :key => 'secret_key',
    #   }
    #
    #   access = client.assertion.get_token(claimset, encoding)
    #   access.token                 # actual access_token string
    #   access.get("/api/stuff")     # making api calls with access token in header
    #
    class Assertion < Base
      # Not used for this strategy
      #
      # @raise [NotImplementedError]
      def authorize_url
        raise(NotImplementedError, 'The authorization endpoint is not used in this strategy')
      end

      # Retrieve an access token given the specified client.
      #
      # @param [Hash] claims the hash representation of the claims that should be encoded as a JWT (JSON Web Token)
      #
      # For reading on JWT and claim keys:
      #   @see https://github.com/jwt/ruby-jwt
      #   @see https://tools.ietf.org/html/rfc7519#section-4.1
      #   @see https://tools.ietf.org/html/rfc7523#section-3
      #   @see https://www.iana.org/assignments/jwt/jwt.xhtml
      #
      # There are many possible claim keys, and applications may ask for their own custom keys.
      # Some typically required ones:
      #   :iss (issuer)
{'fraction_non_alphanumeric': 0.11467116357504216, 'fraction_numerical': 0.020798201236649803, 'mean_word_length': 2.0135478408128704, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7369225', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1083, 'n_words': 281}