Class: JWT::Encode

Inherits:
Object
  • Object
show all
Defined in:
lib/jwt/encode.rb

Overview

Encoding logic for JWT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload, key, algorithm, header_fields) ⇒ Encode

Returns a new instance of Encode.



15
16
17
18
19
20
21
# File 'lib/jwt/encode.rb', line 15

def initialize(payload, key, algorithm, header_fields)
  @payload = payload
  @key = key
  @algorithm = algorithm
  @header_fields = header_fields
  @segments = encode_segments
end

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



9
10
11
# File 'lib/jwt/encode.rb', line 9

def algorithm
  @algorithm
end

#header_fieldsObject (readonly)

Returns the value of attribute header_fields.



9
10
11
# File 'lib/jwt/encode.rb', line 9

def header_fields
  @header_fields
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/jwt/encode.rb', line 9

def key
  @key
end

#payloadObject (readonly)

Returns the value of attribute payload.



9
10
11
# File 'lib/jwt/encode.rb', line 9

def payload
  @payload
end

#segmentsObject (readonly)

Returns the value of attribute segments.



9
10
11
# File 'lib/jwt/encode.rb', line 9

def segments
  @segments
end

Class Method Details

.base64url_encode(str) ⇒ Object



11
12
13
# File 'lib/jwt/encode.rb', line 11

def self.base64url_encode(str)
  Base64.encode64(str).tr('+/', '-_').gsub(/[\n=]/, '')
end