不久前一起破解了一些可行的方法,但肯定不会赢得任何优雅奖。已对其进行了修改以将用户也分配给 Okta 应用程序。如果您正在审核/加入其他公司/目录数据,这很有用。
library(jsonlite)
library(dplyr)
library(httr)
library(purrr)
library(stringi)
library(tidyr)
# create character vector to hold URLs we'll use later when we GET content
url_list <- as.character()
# list placeholder for GET content
okta_content <- list()
# initial URL construction parts for first URL
okta_urllimit = as.character("200")
okta_baseurl <- paste0("https://<your company>.okta.com/api/v1/users?limit=",okta_urllimit)
# next URL construction parts for 'next' URLs
basenexturl <- "https://<your company>.okta.com/api/v1/users?after="
baselimiturl <- "&limit=200"
# Pass initial URL to get first batch
okta_get01 <- httr::GET(okta_baseurl,
config = (
add_headers(Authorization = "SSWS <your Okta API key>")))
# append the URL vector
url_list <- append(url_list, okta_baseurl)
# unlist the all_headers list element from the URL
testallheaders <- as.character(unlist(okta_get01$all_headers))
okta_content <- append(okta_content,content(okta_get01))
# if "next" is in the second link URL (testallheaders[16]) then iterate for as long as
# the next URL header element has "next" in it
while (
grepl("next",testallheaders[16]) == 'TRUE'
)
{
# parse the sha value
testparsenext <- regmatches(testallheaders[16], gregexpr('(?<=after=).*?(?=&limit)',testallheaders[16], perl=T))[[1]]
# and create URL
oktaurlnext <- paste0(basenexturl,testparsenext,baselimiturl)
# iterate and replace 'okta_baseurl' with each subsquent oktaurlnext
okta_get01 <- httr::GET(oktaurlnext,
config = (
add_headers(Authorization = "SSWS <your Okta API key>")))
testallheaders <- as.character(unlist(okta_get01$all_headers))
url_list <- append(url_list, oktaurlnext)
okta_content <- append(okta_content,content(okta_get01))
next
}
# Parse the results into something usable
oktagettojson <- toJSON(okta_content, simplifyDataFrame = TRUE, flatten = TRUE, recursive = TRUE)
oktagetdf <- fromJSON(oktagettojson, simplifyDataFrame = TRUE, flatten = TRUE)
dfnames <- names(oktagetdf)
oktagetdf <- oktagetdf %>% map_if(is.list, as.character)
oktagetdf <- do.call(cbind, lapply(oktagetdf, data.frame, stringsAsFactors=FALSE))
names(oktagetdf) <- dfnames
# adding columns to separate AD domain mastered account and domain names
oktagetdf <- separate(oktagetdf, profile.login,
into = c("credPrefix", "credSuffix"), sep = "@", remove = FALSE, extra = "drop")
# select some data frame columns of interest
okta_allusers <- subset(oktagetdf, select = c("id","status","created","lastLogin","profile.login","credPrefix", "credSuffix","profile.firstName","profile.lastName","profile.email","credentials.provider.type","credentials.provider.name"))