-
Notifications
You must be signed in to change notification settings - Fork 2
/
authentication.R
29 lines (24 loc) · 1.2 KB
/
authentication.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#' Authentication
#'
#' Set up your Client-ID and Secret or forget them.
#' @name authentication
#' @references https://dev.twitch.tv/docs/authentication/
#' @details If, for some reason, you need to change what client-ID you're making calls with, use use \code{\link{twitch_auth_forget}} and then reuse this function to set the new client-ID. Check the link in references to understand what is a client-ID, how it works and how to get one.
#' @export
twitch_auth = function(){
client_id <- Sys.getenv("TWITCH_CLIENT_ID")
client_secret <- Sys.getenv("TWITCH_CLIENT_SECRET")
if (client_id == "" | client_secret == ""){
stop("Please add TWITCH_CLIENT_ID and TWITCH_CLIENT_SECRET to your environment variables (see documentation for reference).")
}
o <- httr::POST("https://id.twitch.tv/oauth2/token",
query = query_list(client_id=client_id,
client_secret = client_secret,
grant_type="client_credentials")) %>% content()
httr::set_config(httr::add_headers('Client-ID' = client_id, Authorization=paste0("Bearer ",o$access_token)))
}
#' @rdname authentication
#' @export
twitch_auth_forget = function(){
httr::reset_config()
}