Actualiser app.R
This commit is contained in:
parent
1df543badc
commit
10edac8998
51
app.R
51
app.R
|
@ -79,14 +79,6 @@ ui <- fluidPage(
|
||||||
'),
|
'),
|
||||||
|
|
||||||
|
|
||||||
# Ici on a créé une fonction permettant de masquer tous les éléments de la page
|
|
||||||
extendShinyjs(text = "
|
|
||||||
shinyjs.hideAllElements = function() {
|
|
||||||
$('body > *').hide();
|
|
||||||
}
|
|
||||||
",functions="shinyjs.hideAllElements"),
|
|
||||||
|
|
||||||
|
|
||||||
#theme = shinytheme("readable"),
|
#theme = shinytheme("readable"),
|
||||||
navbarPage(
|
navbarPage(
|
||||||
"Stat Plateform",
|
"Stat Plateform",
|
||||||
|
@ -274,50 +266,7 @@ server <- function(input, output, session) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
observe({
|
|
||||||
# Vérifier si aucun paramètre n'est présent dans l'URL
|
|
||||||
if (!grepl("^[?&].*", session$clientData$url_search)) {
|
|
||||||
random_bytes <- rand_bytes(16)
|
|
||||||
random_state <- toupper(paste0(sprintf("%02x", as.integer(random_bytes)), collapse = ""))
|
|
||||||
scope <- "openid profile"
|
|
||||||
auth_url <- sprintf("%s?client_id=%s&scope=%s&redirect_uri=%s&response_type=%s&state=%s",
|
|
||||||
authorize_url,client_id, scope, URLencode(uri_url), response_type, random_state)
|
|
||||||
jscommand <- sprintf("window.location.href ='%s';",auth_url)
|
|
||||||
print(jscommand)
|
|
||||||
runjs(jscommand)
|
|
||||||
|
|
||||||
} else if (grepl("\\bcode\\b", session$clientData$url_search)) {
|
|
||||||
|
|
||||||
|
|
||||||
authorization = base64enc::base64encode(charToRaw(paste0(client_id,":",client_secret)))
|
|
||||||
authorization = paste("Basic",authorization)
|
|
||||||
code=param_get(session$clientData$url_search,'code')[[1]]
|
|
||||||
body = list(
|
|
||||||
'grant_type' = 'authorization_code',
|
|
||||||
'redirect_uri' = 'http://localhost:8080',
|
|
||||||
'code' = code,
|
|
||||||
'state' = random_state
|
|
||||||
)
|
|
||||||
headers = c(
|
|
||||||
'Accept' = 'application/json',
|
|
||||||
'Content-Type' = 'application/x-www-form-urlencoded',
|
|
||||||
'Authorization' = authorization
|
|
||||||
)
|
|
||||||
res <- VERB("POST", url = "https://pcis.okta.com/oauth2/default/v1/token", body = body, add_headers(headers), encode = 'form')
|
|
||||||
if (res$status_code == 200){
|
|
||||||
res_content <- content(res,"parsed",encoding = "UTF-8")
|
|
||||||
headers2 = c("Authorization" = paste("Bearer",res_content$access_token))
|
|
||||||
res2 <- VERB("GET",url="https://pcis.okta.com/oauth2/default/v1/userinfo",add_headers(headers2))
|
|
||||||
print(res2)
|
|
||||||
name = content(res2, "parsed", encoding = "UTF-8")$name
|
|
||||||
output$welcome <- renderText({paste("Bonjour",name)})
|
|
||||||
session$userData$authorize = 1
|
|
||||||
} else {
|
|
||||||
print('Vous n avez pas l autorisation')
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
# Partie permettant de fusionner les fichiers
|
# Partie permettant de fusionner les fichiers
|
||||||
observe({
|
observe({
|
||||||
if (session$userData$authorize == 0) {
|
if (session$userData$authorize == 0) {
|
||||||
|
|
Loading…
Reference in New Issue