class Keycard::Token
Holds utility methods for parsing tokens from header values
Constants
- TOKEN_DELIMS
Public Class Methods
rfc7235(string)
click to toggle source
# File lib/keycard/token.rb, line 8 def rfc7235(string) string .sub(/^(Bearer|Token):?/, '') .split(TOKEN_DELIMS) .map { |assignment| split_assignment(assignment) } .to_h["token"] end
Private Class Methods
clean_assignment(string_assignment)
click to toggle source
@param string_assignment [String] of the form 'key=“value”' @return [String] With the quotes and extraneous whitespace removed.
# File lib/keycard/token.rb, line 29 def clean_assignment(string_assignment) string_assignment .delete('"') .strip end
split_assignment(string_assignment)
click to toggle source
@param string_assignment [String] of the form 'key=“value”' @return An array of pairs of key:value, both strings
# File lib/keycard/token.rb, line 20 def split_assignment(string_assignment) clean_assignment(string_assignment) .split('=') .push('') .slice(0, 2) end