Skip to content

Commit

Permalink
Support configurable OSM OAuth2 scope
Browse files Browse the repository at this point in the history
This allows for customization of the OSM OAuth2 scope via the conf (osm.oauth2Scope) or an environment variable (MR_OSM_OAUTH2SCOPE).
At times the oauth2 scope needs reduced, for example a local dev or staging environment, to avoid accidentally publishing test data to OSM.
  • Loading branch information
ljdelight committed Sep 6, 2023
1 parent bf463bf commit 15ced15
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/AuthController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class AuthController @Inject() (
"client_id" -> clientId,
"response_type" -> "code",
"redirect_uri" -> config.getMRFrontend,
"scope" -> "read_prefs write_prefs write_api",
"scope" -> config.getOSMOauth.scope,
"state" -> state
)

Expand Down
7 changes: 5 additions & 2 deletions app/org/maproulette/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ case class OSMOAuth(
requestTokenURL: String,
accessTokenURL: String,
authorizationURL: String,
consumerKey: ConsumerKey
consumerKey: ConsumerKey,
scope: String
)

case class OSMQLProvider(providerURL: String, requestTimeout: Duration)
Expand Down Expand Up @@ -156,7 +157,8 @@ class Config @Inject() (implicit val configuration: Configuration) {
ConsumerKey(
this.config.getOptional[String](Config.KEY_OSM_CONSUMER_KEY).get,
this.config.getOptional[String](Config.KEY_OSM_CONSUMER_SECRET).get
)
),
this.config.getOptional[String](Config.KEY_OSM_OAUTH2_SCOPE).get
)
}
lazy val getOSMQLProvider: OSMQLProvider = OSMQLProvider(
Expand Down Expand Up @@ -357,6 +359,7 @@ object Config {
val KEY_OSM_AUTHORIZATION_URL = s"$GROUP_OSM.authorizationURL"
val KEY_OSM_CONSUMER_KEY = s"$GROUP_OSM.consumerKey"
val KEY_OSM_CONSUMER_SECRET = s"$GROUP_OSM.consumerSecret"
val KEY_OSM_OAUTH2_SCOPE = s"$GROUP_OSM.oauth2Scope"
val KEY_SKIP_OSM_CHANGESET_SUBMISSION = s"$GROUP_OSM.skipOSMChangesetSubmission"

val GROUP_CHALLENGES = "challenges"
Expand Down
4 changes: 4 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ osm {
consumerKey=${?MR_OAUTH_CONSUMER_KEY}
consumerSecret="CHANGE_ME"
consumerSecret=${?MR_OAUTH_CONSUMER_SECRET}
# By default, maproulette needs to edit the OSM map and to read/write the user's preferences (write is needed to store the user's api key to OSM).
# At times the oauth2 scope needs reduced, for example a local dev or staging environment, to avoid accidentally publishing test data to OSM.
oauth2Scope = "read_prefs write_prefs write_api"
oauth2Scope = ${?MR_OSM_OAUTH2SCOPE}
}

# Evolutions
Expand Down

0 comments on commit 15ced15

Please sign in to comment.