Skip to content

Commit

Permalink
add a default google project to help with #81
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEdmondson1234 committed Nov 23, 2017
1 parent c987253 commit 30394b6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Expand Up @@ -15,3 +15,4 @@ test_signedurls.RData
^_pkgdown\.yml$
^_gcssave\.yaml$
^.Rhistory$
^gcs\.oauth$
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@
.httr-oauth-SUSPENDED
inst/doc
auth.json
gcs.oauth
1 change: 1 addition & 0 deletions NEWS.md
@@ -1,6 +1,7 @@
# googleCloudStorage 0.4.0.9000

* Make `gcs_auth()` more forgiving
* Add a default google cloud project

# googleCloudStorageR 0.4.0

Expand Down
16 changes: 13 additions & 3 deletions R/options.R
Expand Up @@ -5,9 +5,19 @@
}

.onAttach <- function(libname, pkgname){

attempt <- try(googleAuthR::gar_attach_auto_auth("https://www.googleapis.com/auth/devstorage.full_control",
environment_var = "GCS_AUTH_FILE"))

suppressMessages(
googleAuthR::gar_set_client(system.file("client","googleAuthR_nobilling_client.json",
package = "googleCloudStorageR"),
scopes = "https://www.googleapis.com/auth/devstorage.full_control")
)

options(googleAuthR.httr_oauth_cache = "gcs.oauth")

attempt <- try(
googleAuthR::gar_attach_auto_auth("https://www.googleapis.com/auth/devstorage.full_control",
environment_var = "GCS_AUTH_FILE")
)

if(inherits(attempt, "try-error")){
warning("Problem using auto-authentication when loading from GCS_AUTH_FILE: \n", attempt, "
Expand Down
1 change: 1 addition & 0 deletions inst/client/googleAuthR_nobilling_client.json
@@ -0,0 +1 @@
{"installed":{"client_id":"201908948134-rm1ij8ursrfcbkv9koc0aqver84b04r7.apps.googleusercontent.com","project_id":"g-auth-r","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"nksRJZ5K3nm9FUWsAtBoBArz","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
41 changes: 22 additions & 19 deletions vignettes/googleCloudStorageR.Rmd
Expand Up @@ -31,29 +31,11 @@ Sys.setenv("GCS_CLIENT_ID" = "mykey",

These can alternatively be set on the command line or via an Renviron.site or .Renviron file (`https://cran.r-project.org/web/packages/httr/vignettes/api-packages.html`).

## Authentication

Authentication can be carried out each session via `gcs_auth`. The first time you run this you will be sent to a Google login prompt in your browser to allow the `googleCloudStorageR` project access (or the Google project you configure).

Once authenticated a file named `.httr-oauth` is saved to your working directory. On subsequent authentication this file will hold your authentication details, and you won't need to go via the browser. Deleting this file, or setting `new_user=TRUE` will start the authentication flow again.

```r
library(googleCloudStorageR)
## first time this will send you to the browser to authenticate
gcs_auth()

## to authenticate with a fresh user, delete .httr-oauth or run with new_user=TRUE
gcs_auth(new_user = TRUE)

...call functions...etc...

```

Each new R session will need to run `gcs_auth()` to authenticate future API calls.

### Auto-authentication

Alternatively, you can specify the location of a service account JSON file taken from your Google Project, or the location of a previously created `.httr-oauth` token in a system environment:
The best method for authentication is to use your own Google Cloud Project. You can specify the location of a service account JSON file taken from your Google Project, or the location of a previously created `gcs.oauth` token in a system environment:

Sys.setenv("GCS_AUTH_FILE" = "/fullpath/to/auth.json")

Expand All @@ -65,9 +47,30 @@ library(googleCloudStorageR)

## no need for gcs_auth()
gcs_get_bucket("your-bucket")
```

If using your own `gcs.oauth` file you will also need to set the client ID and secret. This is easiest done using `googleAuthR::gar_set_client()` - see its help for details.

## Manual Authentication

Authentication can be carried out each session via `gcs_auth`. The first time you run this you will be sent to a Google login prompt in your browser to allow the `googleCloudStorageR` project access (or the Google project you configure).

Once authenticated a file named `gcs.oauth` is saved to your working directory. On subsequent authentication this file will hold your authentication details, and you won't need to go via the browser. Deleting this file, or setting `new_user=TRUE` will start the authentication flow again.

```r
library(googleCloudStorageR)
## first time this will send you to the browser to authenticate
gcs_auth()

## to authenticate with a fresh user, delete gcs.oauth or run with new_user=TRUE
gcs_auth(new_user = TRUE)

...call functions...etc...

```

Each new R session will need to run `gcs_auth()` to authenticate future API calls.

## Examples

### Setting a default Bucket
Expand Down

0 comments on commit 30394b6

Please sign in to comment.