Module: Doorkeeper::OAuth::Helpers::UniqueToken

Defined in:
lib/doorkeeper/oauth/helpers/unique_token.rb

Overview

Default Doorkeeper token generator. Follows OAuth RFC and could be customized using `default_generator_method` in configuration.

Class Method Summary collapse

Class Method Details

.default_generator_methodObject

Generator method for default generator class (SecureRandom)


24
25
26
# File 'lib/doorkeeper/oauth/helpers/unique_token.rb', line 24

def self.default_generator_method
  Doorkeeper.config.default_generator_method
end

.generate(options = {}) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/doorkeeper/oauth/helpers/unique_token.rb', line 10

def self.generate(options = {})
  # Access Token value must be 1*VSCHAR or
  # 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) *"="
  #
  # @see https://tools.ietf.org/html/rfc6749#appendix-A.12
  # @see https://tools.ietf.org/html/rfc6750#section-2.1
  #
  generator = options.delete(:generator) || SecureRandom.method(default_generator_method)
  token_size = options.delete(:size) || 32
  generator.call(token_size)
end