-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
88 lines (68 loc) · 2.41 KB
/
README.Rmd
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# connectcreds
<!-- badges: start -->
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![R-CMD-check](https://github.com/posit-dev/connectcreds/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/posit-dev/connectcreds/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
`connectcreds` provides low-level utilities for Shiny developers and R package
authors building tools that make use of Posit Connect's [viewer-based
credentials](https://docs.posit.co/connect/admin/integrations/oauth-integrations/).
## Installation
You can install connectcreds from CRAN with:
``` r
install.packages("connectcreds")
```
Or, install the development version of connectcreds from
[GitHub](https://github.com/) with:
``` r
# install.packages("pak")
pak::pak("posit-dev/connectcreds")
```
## Usage
`connectcreds` includes helper functions for implementing Posit Connect's
viewer-based credentials in Shiny applications. These helpers are meant to be
called in the context of a Shiny server function, as follows:
```{r shiny-server-fn}
server <- function(input, output, session) {
token <- "PAT for local development"
if (connectcreds::has_viewer_token()) {
token <- connectcreds::connect_viewer_token()
}
# ...
}
```
Usually, though, these helpers will be used internally by packages that
authenticate with various services. For example, here is a simplified version of
`gh::gh_token()` that returns a GitHub OAuth token for the viewer on Connect but
uses a GitHub personal access token when testing locally:
```{r gh-token}
gh_token <- function() {
rlang::check_installed("connectcreds", "for viewer-based authentication")
if (connectcreds::has_viewer_token("https://github.com")) {
token <- connectcreds::connect_viewer_token("https://github.com")
return(token$access_token)
}
Sys.getenv("GITHUB_PAT")
}
server <- function(input, output, session) {
# A Shiny output that shows the user's GitHub username:
output$gh_handle <- renderText({
resp <- gh::gh_whoami(.token = gh_token())
resp$login
})
# ...
}
```
## License
MIT (c) [Posit Software, PBC](https://posit.co)