Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add authorization grant refreshing token #693

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

clemens-tolboom
Copy link
Collaborator

No description provided.

@clemens-tolboom clemens-tolboom linked an issue Mar 12, 2024 that may be closed by this pull request
2 tasks
@clemens-tolboom clemens-tolboom added this to the Sprint 218 milestone Mar 12, 2024
@timcadman
Copy link
Contributor

This fails after 15 mins with the message:

! There are some DataSHIELD errors, list them with datashield.errors()
Run `rlang::last_trace()` to see where the error occurred.
> datashield.errors()
$study1
[1] "Unauthorized"

To reproduce:

library(dsBaseClient)
library(purrr)

demo_url <- "https://armadillo-demo.molgenis.net/"
demo_token <- armadillo.get_token(demo_url)

builder <- DSI::newDSLoginBuilder()
builder$append(server = "study1", url = demo_url, profile = "xenon", token = demo_token, driver = "ArmadilloDriver", 
               table = "xenon-tests/2_1-core-1_0/nonrep")
logindata <- builder$build()

conns <- DSI::datashield.login(logins = logindata, assign = T, symbol = "nonrep")

1:100000 %>% map(
  ~ds.rep(x1 = 4, times = 6, length.out = NA, each = 1, source.x1 = "clientside",
          source.times = "c", source.length.out = NULL, source.each = "c",
          x1.includes.characters = FALSE, newobj = "rep.seq"))

@clemens-tolboom
Copy link
Collaborator Author

Error in `map()`:
ℹ In index: 3452.
Caused by error:
! There are some DataSHIELD errors, list them with datashield.errors()
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/purrr_error_indexed>
Error in `map()`:
ℹ In index: 1.
Caused by error:
! There are some DataSHIELD errors, list them with datashield.errors()
---
Backtrace:
     ▆
  1. ├─1:1e+05 %>% ...
  2. └─purrr::map(...)
  3.   └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
  4.     ├─purrr:::with_indexed_errors(...)
  5.     │ └─base::withCallingHandlers(...)
  6.     ├─purrr:::call_with_cleanup(...)
  7.     └─.f(.x[[i]], ...)
  8.       └─dsBaseClient::ds.rep(...)
  9.         └─DSI::datashield.assign(datasources, newobj, calltext)
 10.           └─DSI::datashield.assign.expr(...)
 11.             └─DSI:::.checkLastErrors()
 12.               └─base::stop(...)
Run rlang::last_trace(drop = FALSE) to see 4 hidden frames.
> rlang::last_trace(drop = FALSE)
<error/purrr_error_indexed>
Error in `map()`:
ℹ In index: 1.
Caused by error:
! There are some DataSHIELD errors, list them with datashield.errors()
---
Backtrace:
     ▆
  1. ├─1:1e+05 %>% ...
  2. ├─purrr::map(...)
  3. │ └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
  4. │   ├─purrr:::with_indexed_errors(...)
  5. │   │ └─base::withCallingHandlers(...)
  6. │   ├─purrr:::call_with_cleanup(...)
  7. │   └─.f(.x[[i]], ...)
  8. │     └─dsBaseClient::ds.rep(...)
  9. │       └─DSI::datashield.assign(datasources, newobj, calltext)
 10. │         └─DSI::datashield.assign.expr(...)
 11. │           └─DSI:::.checkLastErrors()
 12. │             └─base::stop(...)
 13. └─base::.handleSimpleError(...)
 14.   └─purrr (local) h(simpleError(msg, call))
 15.     └─cli::cli_abort(...)
 16.       └─rlang::abort(...)

@clemens-tolboom
Copy link
Collaborator Author

clemens-tolboom commented Mar 13, 2024

1:100000 %>% map(
  ~{
    Sys.sleep(10)
    print(.)
    print(format(Sys.time(), "%Y-%m-%dT%H:%M:%S"))
    ds.rep(x1 = 4, times = 6, length.out = NA, each = 1, source.x1 = "clientside",
          source.times = "c", source.length.out = NULL, source.each = "c",
          x1.includes.characters = FALSE, newobj = "rep.seq")
  })

running again

[1] 1
[1] "2024-03-13T10:01:47"
  Assigned expr. (rep.seq <- repDS(x1.transmit = "4", times.transmit = "6", length.out.transmit =...
  Aggregated (testObjExistsDS("rep.seq")) [==============================================] 100% / 0s
  Aggregated (messageDS("rep.seq")) [====================================================] 100% / 0s

...

[1] 93
[1] "2024-03-13T10:17:40"
  Assigned expr. (rep.seq <- repDS(x1.transmit = "4", times.transmit = "6", length.out.transmit =...Error in `map()`:
ℹ In index: 93.
Caused by error:
! There are some DataSHIELD errors, list them with datashield.errors()
Run `rlang::last_trace()` to see where the error occurred.

17:40 - 1:47 = 15:53 ... so our timeout of 15 minutes checks

@clemens-tolboom
Copy link
Collaborator Author

After some puzzling got this running on DEV

#!/usr/bin/env Rscript

library(dsBaseClient)
library(purrr)

#demo_url <- "https://armadillo-demo.molgenis.net/"
demo_url <- "http://localhost:8080/"
demo_token <- armadillo.get_token(demo_url)

builder <- DSI::newDSLoginBuilder()
builder$append(server = "study1", url = demo_url, profile = "default", token = demo_token, driver = "ArmadilloDriver", 
               table = "lifecycle/core/nonrep")
logindata <- builder$build()

conns <- DSI::datashield.login(logins = logindata, assign = T, symbol = "nonrep")

1:100000 %>% map(
  ~{
    Sys.sleep(10)
    print(.)
    print(format(Sys.time(), "%Y-%m-%dT%H:%M:%S"))
    ds.rep(x1 = 4, times = 6, length.out = NA, each = 1, source.x1 = "clientside",
          source.times = "c", source.length.out = NULL, source.each = "c",
          x1.includes.characters = FALSE, newobj = "rep.seq")
  })

@clemens-tolboom
Copy link
Collaborator Author

grep -i auth.molgenis.org logs/armadillo.log

gives

2024-03-13 11:06:29.622 [main|] DEBUG o.s.web.client.RestTemplate - HTTP GET https://oidc-provider/.well-known/openid-configuration

...

2024-03-13 11:11:45.077 [http-nio-8080-exec-10|] DEBUG o.s.web.client.RestTemplate - HTTP GET https://oidc-provider/.well-known/jwks.json
...

Guess that's a config poll for changes on the OIDC provider.

@clemens-tolboom clemens-tolboom marked this pull request as draft March 13, 2024 13:05
@clemens-tolboom clemens-tolboom removed this from the Sprint 218 milestone Mar 13, 2024
@clemens-tolboom
Copy link
Collaborator Author

Test did not succeed as using different OICD does not help while testing.

@mswertz mswertz changed the title Add authorization grant refreshing token fix: add authorization grant refreshing token Mar 19, 2024
@clemens-tolboom clemens-tolboom added this to the Sprint 219 milestone Mar 21, 2024
@marikaris marikaris modified the milestones: Sprint 219, Backlog May 7, 2024
@mswertz
Copy link
Member

mswertz commented May 14, 2024

we believe it is better to stop 'molgenisAuth.r' and instead use htt2 in both molgenis-r-armadillo and molgenis-r-datashield.

httr2 has device workflow and refresh token capabilities.

Copy link

sonarcloud bot commented May 14, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As armadillo user I want to refresh my tokens when they timeout
4 participants