Method: MagicAdmin::Resource::Token#decode

Defined in:
lib/magic-admin/resource/token.rb

#decode(did_token) ⇒ Object

Description:

Method Decodes a DID Token from a Base64 string into
a tuple of its individual components: proof and claim.
This method allows you decode the DID Token
and inspect the token

Arguments:

did_token: A DID Token generated by a Magic user on the client-side.

Returns:

An array containing proof and claim or raise an error


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/magic-admin/resource/token.rb', line 61

def decode(did_token)
  proof = nil
  claim = nil
  begin
    token_array = JSON.parse(base64_decode(did_token))
    proof = token_array[0]
    claim = JSON.parse(token_array[1])
    validate_claim_fields!(claim)
  rescue JSON::ParserError, ArgumentError
    raise DIDTokenError, "DID Token is malformed"
  end
  [proof, claim]
end