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

Implement OAuth2 authentication #1

Merged
merged 2 commits into from Jul 5, 2023
Merged

Implement OAuth2 authentication #1

merged 2 commits into from Jul 5, 2023

Conversation

jmaspons
Copy link
Owner

@jmaspons jmaspons commented Jul 4, 2023

I tried to make the authentication without the OAuth secret (see below), but it fails. So the secret is saved obfuscated.

library(osmapiR)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright

token_url <- httr2::req_url_path(
  req = httr2::request(base_url = getOption("osmapir.base_auth_url")),
  "oauth2", "token"
)$url

client <- httr2::oauth_client(
  id = getOption("osmapir.oauth_id"),
  token_url = token_url,
  name = "osmapiR"
)

auth_url <- httr2::req_url_path(
  req = httr2::request(base_url = getOption("osmapir.base_auth_url")),
  "oauth2", "authorize"
)$url

token <- httr2::oauth_flow_auth_code(
  client = client,
  auth_url = auth_url,
  scope = paste(c("read_prefs", "write_prefs", "write_api", "read_gpx", "write_gpx", "write_notes"), collapse = " "),
  pkce = TRUE,
  host_name = "127.0.0.1"
)
#> Waiting for authentication in browser...
#> Press Esc/Ctrl + C to abort
#> Error in `oauth_flow_abort()`:
#> ! OAuth failure [invalid_client]
#> • Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method.
#> Run `rlang::last_trace()` to see where the error occurred.
token
#> Error in eval(expr, envir, enclos): object 'token' not found

logout_osmapi()

Secrets are obfuscated. The app is registered at osm.org as non-confidential
… API calls osm_permissions() & osm_details_logged_user()
@jmaspons
Copy link
Owner Author

jmaspons commented Jul 5, 2023

Seems that it should work without the secret openstreetmap/openstreetmap-website#3494 (comment)

@jmaspons jmaspons merged commit 079140b into main Jul 5, 2023
@jmaspons jmaspons deleted the oauth2 branch July 5, 2023 18:53
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.

None yet

1 participant