﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
23538	Some 'OAuth 2' access tokens work, while others do not	Rub21	Rub21	"Currently, I am working on integrating OHM-staging API with JOSM using OAuth2. The API is https://staging.openhistoricalmap.org/api For some reason, some ""OAuth 2 applications"" do not work; they throw an error. Luckily, I found one that works. It could be assumed that it's a problem with the OHM-API. However, when I changed ""OAuth 2"" to ""OSM-API"" in JOSM, it throws the same error as in the OHM-staging API. Here is the reference: https://github.com/OpenHistoricalMap/issues/issues/610#issuecomment-1979859527 

Create a ""OAuth 2 applications"", in OSM-API

- Permissions	
      Read user preferences (read_prefs)
      Modify user preferences (write_prefs)
      Create diary entries, comments and make friends (write_diary)
      Modify the map (write_api)
      Read private GPS traces (read_gpx)
      Upload GPS traces (write_gpx)
      Modify notes (write_notes)
- Redirect URIs	
      http://127.0.0.1:8111/oauth_authorization
  

Lets use the token created in JOSM config for authorization 

What steps will reproduce the problem? 

 - Download latest JOSM Latest
 - preferences / OSM Server / Display Advanced OAuth Parameters (do not activate the button to get thetoken)
- preferences / OSM Server / Authorize now (Manual)/Advanced OAuth Parameters (do not activate the button Test Access token)



Since I couldn't test the token directly in the JOSM UI, I hardcoded the token.


- Clone the JOSM repo, and we need to change this line: https://github.com/JOSM/josm/blob/master/src/org/openstreetmap/josm/data/oauth/OAuthParameters.java#L129
 with the new access token. Then, build a JAR file.


- Run JOSM and test the authorization.

[[Image(https://github.com/OpenHistoricalMap/issues/assets/1152236/cfe883bd-a3f8-4dac-b745-d0482307750a)]]


```
{{{
Revision:19015
Is-Local-Build:true
Build-Date:2024-03-08 08:53:19

Identification: JOSM/1.5 (19015 SVN en) Mac OS X 13.0
OS Build number: macOS 13.0 (22A8380)
Memory Usage: 396 MB / 4096 MB (182 MB allocated, but free)
Java version: 17.0.9+8-LTS, Azul Systems, Inc., OpenJDK 64-Bit Server VM
Look and Feel: com.apple.laf.AquaLookAndFeel
Screen: Display 1 1512×982 (scaling 2.00×2.00) Display 2 1920×1080 (scaling 1.00×1.00) Display 3 1920×1080 (scaling 1.00×1.00)
Maximum Screen Size: 1920×1080
Best cursor sizes: 16×16→16×16, 32×32→32×32
Environment variable LANG: en_US.UTF-8
System property file.encoding: UTF-8
System property sun.jnu.encoding: UTF-8
Locale info: en_US
Numbers with default locale: 1234567890 -> 1234567890

Plugins:
+ FastDraw
+ apache-commons
+ buildings_tools
+ continuosDownload
+ ejml
+ geotools
+ jackson
+ jaxb
+ josm_magic_wand
+ jts
+ opendata
+ osm-obj-info
+ scripting
+ utilsplugin2

Map paint styles:
+ https://gist.githubusercontent.com/karitotp/728f688f2df8a30d449cd7189f92c80c/raw/4c3833b84c05749ec7a25e70a59d24c758fa2ea5/reforestamos_mexico.mapcss

Last errors/warnings:
- 00091.210 E: 	at java.desktop/java.awt.Container.add(Container.java:1001)
- 00091.210 E: 	at java.desktop/javax.swing.JOptionPane.initDialog(JOptionPane.java:987)
- 00091.210 E: 	at java.desktop/javax.swing.JOptionPane.createDialog(JOptionPane.java:978)
- 00091.210 E: 	at java.desktop/javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:877)
- 00091.210 E: 	at org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.checkPermission(RequestHandler.java:213)
- 00091.210 E: 	at org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.handle(RequestHandler.java:86)
- 00091.210 E: 	at org.openstreetmap.josm.io.remotecontrol.RequestProcessor.run(RequestProcessor.java:266)
- 00154.522 E: Handled by bug report queue: jakarta.json.stream.JsonParsingException: Invalid token=EOF at (line no=1, column no=0, offset=-1). Expected tokens are: [CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]
- 00160.295 E: Handled by bug report queue: jakarta.json.stream.JsonParsingException: Invalid token=EOF at (line no=1, column no=0, offset=-1). Expected tokens are: [CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]
- 00251.808 E: Handled by bug report queue: jakarta.json.stream.JsonParsingException: Invalid token=EOF at (line no=1, column no=0, offset=-1). Expected tokens are: [CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]



=== REPORTED CRASH DATA ===
BugReportExceptionHandler#handleException:
No data collected.

Warning issued by: BugReportExceptionHandler#handleException

=== STACK TRACE ===
Thread: RemoteControl request processor (83)
jakarta.json.stream.JsonParsingException: Invalid token=EOF at (line no=1, column no=0, offset=-1). Expected tokens are: [CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL]
	at org.eclipse.parsson.JsonParserImpl.parsingException(JsonParserImpl.java:455)
	at org.eclipse.parsson.JsonParserImpl.access$1000(JsonParserImpl.java:53)
	at org.eclipse.parsson.JsonParserImpl$NoneContext.getNextEvent(JsonParserImpl.java:443)
	at org.eclipse.parsson.JsonParserImpl.next(JsonParserImpl.java:363)
	at org.eclipse.parsson.JsonReaderImpl.read(JsonReaderImpl.java:63)
	at org.openstreetmap.josm.data.oauth.OAuth20Token.<init>(OAuth20Token.java:57)
	at org.openstreetmap.josm.data.oauth.OAuth20Authorization$OAuth20AuthorizationHandler.handleRequest(OAuth20Authorization.java:100)
	at org.openstreetmap.josm.io.remotecontrol.handler.AuthorizationHandler.handleRequest(AuthorizationHandler.java:130)
	at org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.handle(RequestHandler.java:87)
	at org.openstreetmap.josm.io.remotecontrol.RequestProcessor.run(RequestProcessor.java:266)
}}}
```

I reckon  that this issues is related to the tokens being generated because I have tested with OHM-staging API. Some tokens work, but others do not.


Github Ticket: https://github.com/OpenHistoricalMap/issues/issues/610#issuecomment-1985755649



"	defect	closed	normal		Core		needinfo	OAuth2 access token	
