Skip to content

Instantly share code, notes, and snippets.

@johndrummond
Last active August 29, 2019 16:28
Show Gist options
  • Save johndrummond/f8a8ffdfd3b807a264c197d929b39a9e to your computer and use it in GitHub Desktop.
Save johndrummond/f8a8ffdfd3b807a264c197d929b39a9e to your computer and use it in GitHub Desktop.
Essentially the code from the example on https://cran.r-project.org/web/packages/jose/vignettes/jwt.html to remember the location and show lists
#example from https://cran.r-project.org/web/packages/jose/vignettes/jwt.html
# check against https://jwt.io/
# and showing arrays work
library(openssl)
library(jose)
# Example payload
claim <- jwt_claim(user = "jeroen", session_key = 123456,
groups = c("fred", "tom", "jane"),
extra = list("f1" = "field1", "f2" = "field2"))
# Encode with hmac
key <- charToRaw("SuperSecret")
jwt <- jwt_encode_hmac(claim, secret = key)
jwt
#take this key and check it in https://jwt.io/
jwt_decode_hmac(jwt, secret = key)
# and decoding working here
#decode errors without the key
key2 <- charToRaw("SuperSecret2")
jwt_decode_hmac(jwt, secret = key2)
#gives an error as no key
#getting the data
(strings <- strsplit(jwt, ".", fixed = TRUE)[[1]])
cat(rawToChar(base64url_decode(strings[1])))
cat(rawToChar(base64url_decode(strings[2])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment