Created
November 7, 2022 19:06
-
-
Save randyphoa/ab51ca33938c747ae1649ae8a368da3f to your computer and use it in GitHub Desktop.
Populate require information in app.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(httr) | |
library(shiny) | |
library(jsonlite) | |
DEPLOYMENT_ID <- "21d4e28f-2e58-4b9b-9d82-5b6938655991" | |
VERSION <- "2022-09-27" | |
SPACE_ID = "399a2bce-40b5-457a-8e18-de978043e2c8" | |
API_KEY = "xxx" | |
CPD_URL = "https://cpd-cpd.itzroks-550003aw18-rmaez9-6ccd7f378ae819553d37d5f2ee142bd6-0000.au-syd.containers.appdomain.cloud" | |
USERNAME = "admin" | |
httr::set_config(httr::config(ssl_verifypeer = FALSE, ssl_verifyhost = FALSE)) | |
getHeaders <- function() { | |
headers <- c("cache-control"="no-cache", "Content-Type"="application/json") | |
url <- stringr::str_interp("${CPD_URL}/icp4d-api/v1/authorize") | |
body <- stringr::str_interp('{"username":"${USERNAME}","api_key":"${API_KEY}"}') | |
r <- POST( | |
url, | |
add_headers( | |
.headers = headers | |
), | |
body=fromJSON(body), | |
encode="json" | |
) | |
token <- httr::content(r)$token | |
headers <- c("Authorization"=stringr::str_interp("Bearer ${token}"), "Content-Type"="application/json", "Accept"="application/json") | |
return(headers) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment