better presentation of common tokens

This commit is contained in:
hong-revo 2019-02-13 05:09:41 +11:00
Родитель b71043e03e
Коммит 5b694428a9
3 изменённых файлов: 33 добавлений и 1 удалений

Просмотреть файл

@ -16,8 +16,15 @@ format_auth_header <- function(token)
version <- if(token$version == 1) "v1.0" else "v2.0"
tenant <- token$tenant
if(tenant == "common")
{
token_obj <- decode_jwt(token$credentials$access_token)
tenant <- paste0(tenant, " / ", token_obj$payload$tid)
}
paste0("Azure Active Directory ", version, " token for ", res, "\n",
" Tenant: ", token$tenant, "\n",
" Tenant: ", tenant, "\n",
" App ID: ", token$client$client_id, "\n",
" Authentication method: ", token$auth_type, "\n",
" Token valid from: ", format(obtained, usetz=TRUE), " to: ", format(expiry, usetz=TRUE), "\n",

Просмотреть файл

@ -47,6 +47,8 @@
#' @rdname guid
normalize_tenant <- function(tenant)
{
tenant <- tolower(tenant)
# check if supplied a guid; if not, check if a fqdn;
# if not, check if 'common'; if not, append '.onmicrosoft.com'
if(is_guid(tenant))

Просмотреть файл

@ -124,3 +124,26 @@ verify_v2_scope <- function(scope)
scope
}
# decode info in a token (which is a JWT object)
decode_jwt <- function(token)
{
decode <- function(string)
{
m <- nchar(string) %% 4
if(m == 2)
string <- paste0(string, "==")
else if(m == 3)
string <- paste0(string, "=")
jsonlite::fromJSON(rawToChar(openssl::base64_decode(string)))
}
token <- as.list(strsplit(token, "\\.")[[1]])
token[1:2] <- lapply(token[1:2], decode)
names(token)[1:2] <- c("header", "payload")
if(length(token) > 2)
names(token)[3] <- "signature"
token
}