Skip to content

Commit

Permalink
Normalize scopes in the hash; fixes #494
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Nov 5, 2017
1 parent 3f07681 commit 2c343d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion R/oauth-token.r
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ Token <- R6::R6Class("Token", list(
# endpoint = which site
# app = client identification
# params = scope
msg <- serialize(list(self$endpoint, self$app, self$params$scope), NULL)
msg <- serialize(
list(self$endpoint, self$app, normalize_scopes(self$params$scope)),
NULL
)

# for compatibility with digest::digest()
paste(openssl::md5(msg[-(1:14)]), collapse = "")
Expand Down Expand Up @@ -349,3 +352,7 @@ TokenServiceAccount <- R6::R6Class("TokenServiceAccount", inherit = Token2.0, li
cache = function(path) self,
load_from_cache = function() self
))

normalize_scopes <- function(x) {
setNames(sort(unique(x)), NULL)
}
4 changes: 3 additions & 1 deletion tests/testthat/test-oauth-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ test_that("use_cache() respects options", {
expect_equal(use_cache(), ".httr-oauth")
})

test_that("token saved to and restored from cache", {
test_that("token saved to and restored from cache, scopes normalized in hash", {
owd <- setwd(tmp_dir())
on.exit(setwd(owd))

token_a <- Token2.0$new(
app = oauth_app("x", "y", "z"),
endpoint = oauth_endpoints("google"),
params = list(scope = c(a = "a", "b")),
cache_path = ".tmp-cache",
credentials = list(a = 1)
)
Expand All @@ -45,6 +46,7 @@ test_that("token saved to and restored from cache", {
token_b <- Token2.0$new(
app = oauth_app("x", "y", "z"),
endpoint = oauth_endpoints("google"),
params = list(scope = c(b = "b", "a")),
cache_path = ".tmp-cache"
)

Expand Down

0 comments on commit 2c343d4

Please sign in to comment.