Class: Jwtauth::Session

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

Class Method Summary collapse

Class Method Details

.expjwt_decode(token) ⇒ Object

begin

decoded_token = JWT.decode token, hmac_secret, true, { :algorithm => 'HS256' }

rescue JWT::ExpiredSignature

# Handle expired token, e.g. logout user or deny access

end



150
151
152
# File 'lib/jwtauth.rb', line 150

def expjwt_decode token
  JWT.decode token, Jwtauth.jwt_rsa_pub, true, { algorithm: Jwtauth.algorithm }
end

.getjwt(origin_request) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/jwtauth.rb', line 154

def getjwt origin_request
  uri = URI(Jwtauth.session_path)

  uri.query = CGI.unescape({
    Jwtauth.headers_names[:'uid'] => origin_request.headers[Jwtauth.headers_names[:'uid']] || origin_request.params[Jwtauth.headers_names[:'uid']],
    Jwtauth.headers_names[:'client'] => origin_request.headers[Jwtauth.headers_names[:'client']] || origin_request.params[Jwtauth.headers_names[:'client']],
    Jwtauth.headers_names[:'access-token'] => origin_request.headers[Jwtauth.headers_names[:'access-token']] || origin_request.params[Jwtauth.headers_names[:'access-token']],
    'namespace' => Jwtauth.namespace,
  }.to_query)

  Net::HTTP.start(uri.host, uri.port,
    :use_ssl => uri.scheme == 'https') do |http|
    request = Net::HTTP::Get.new uri

    response = http.request request
  end
end

.jwt_decode(token) ⇒ Object



141
142
143
# File 'lib/jwtauth.rb', line 141

def jwt_decode token
  JWT.decode token, Jwtauth.jwt_rsa_pub, true, { algorithm: Jwtauth.algorithm }
end