Jwt

Generates JWT (short for Json Web Token) based on valid token transaction signed by both parties and decodes JWT into hash.

Jwt Object

AttributeTypeDescription
secretStringJWT Secret

❗️

Secret Seeds

Make sure you keep all the secret seeds stored safely, extracting into ENV variables or equivalent. Keys present throughout the documentation only serve for example purposes and belong to an account in the Test network.

Constants

ALG = "HS512".freeze

Used JWT algorithm.

Methods

#encode(token) ⇒ String

Encodes token into JWT.


#decode!(jwt) ⇒ Hash

Returns decoded JWT.

# Json Web Token secret
jwt_secret = "431714...5aa8fb"

jwt = Mobius::Client::Auth::Jwt.new(jwt_secret)

# Token
seed = "SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4"
xdr = "AAAAAL...W62kcE"
address = "GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"

token = Mobius::Client::Auth::Token.new(seed, xdr, address)
# =>
<Mobius::Client::Auth::Token:0x00007f90ac841b80
  @seed="SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4",
  @xdr="AAAAAB...sYzQAI",
  @address="GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"
>
  
# Validate token
token.validate!
# =>
true

# Converts issued token into JWT.
# This will be the JWT used by the User in the query param.
user_token = jwt.encode(token)
# =>
eyJ0eX...1YInIQ

# Decodes JWT into hash and User's public key
# Indentifies the user_dapp account to initialize the @app object.
jwt.decode!(user_token)
# =>
<OpenStruct
  hash="a8f68c74b0d2b32b47c8348e56e82f98fa165076d4ec7e8e8f709619d96b34e2",
  public_key="GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y",
  min_time=1530667902, max_time=1530754302
>
// Json Web Token secret
const jwtSecret = '431714...5aa8fb';

const jwt = new Mobius.Auth.Jwt(jwtSecret);

// Token
const seed = 'SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4';
const xdr = 'AAAAAL...W62kcE';
const address = 'GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y';

const token = new Mobius.Auth.Token(seed, xdr, address);

// Validate token
token.validate(); // => true

// Converts issued token into JWT.
// This will be the JWT used by the User in the query param.
const userToken = jwt.encode(token); // => eyJ0eX...1YInIQ

// Decodes JWT into hash and User's public key
// Indentifies the user account to initialize the dapp object.
const jwtDecoded = jwt.decode(userToken); 
/** jwtDecoded => 
  *  {
  *   jti: 'a8f68c74b0d2b32b47c8348e56e82f98fa165076d4ec7e8e8f709619d96b34e2',
  *   sub: 'GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y',
  *   iat: 1530667902,
  *   exp: 1530754302
  *  }
  */

📘

XDR Viewer

xdr