Modify

Opened 2 years ago

Closed 23 months ago

#22730 closed defect (fixed)

Mapillary plugin fails to log in with "Mapillary: Could not refresh login, logging out" popup, "Mapillary: Failed to login: "The parameter grant_type is required."" API exception

Reported by: AntiCompositeNumber Owned by: Don-vip
Priority: normal Milestone:
Component: Plugin http2 Version:
Keywords: template_report OAuth Cc:

Description

When I try to log in to the Mapillary plugin, the Mapillary OAuth grant opens in the browser as normal. I click Allow, and am redirected to a localhost page that says "Login successful, return to JOSM." Upon returning to JOSM, I notice a popup stating "Mapillary: Could not refresh login, logging out".

What steps will reproduce the problem?

  1. Log out of the Mapillary plugin if already logged in
  2. Attempt to log into the Mapillary plugin via OAuth (from the Preferences > Plugins > Mapillary menu)

What is the expected result?

It works

What happens instead?

A "Mapillary: Could not refresh login, logging out" popup appears, and I am not logged in.

Please provide any additional information below. Attach a screenshot if possible.

Relevant debug logs, with secret redacted:

2023-02-11 13:30:14.745 INFO: Opening URL: https://www.mapillary.com/connect?client_id=4280585711960869&response_type=code&scope=read&redirect_uri=http%3A%2F%2Flocalhost%3A8763%2F
2023-02-11 13:30:19.836 FINE: Contacting Server...
2023-02-11 13:30:19.836 INFO: POST https://graph.mapillary.com/token (364 B) ...
2023-02-11 13:30:19.836 FINE: REQUEST HEADERS: {Accept=*/*, Accept-Encoding=gzip, deflate, Authorization=OAuth MLY|4280585711960869|[***]}
2023-02-11 13:30:19.969 INFO: POST https://graph.mapillary.com/token -> HTTP_2 500 (132 ms; 136 B)
2023-02-11 13:30:19.969 FINE: RESPONSE HEADERS: {:status=[500], access-control-allow-origin=[*], alt-svc=[h3=":443"; ma=86400], cache-control=[no-store], content-length=[136], content-type=[application/json; charset=UTF-8], date=[Sat, 11 Feb 2023 18:30:19 GMT], expires=[Sat, 01 Jan 2000 00:00:00 GMT], mapillary-api-version=[v1.0], pragma=[no-cache], priority=[u=3,i], strict-transport-security=[max-age=31536000; preload; includeSubDomains], vary=[Origin], www-authenticate=[OAuth "Facebook Platform" "invalid_request" "The parameter grant_type is required."], x-app-usage=[{"call_volume":0,"cpu_time":0}], x-fb-debug=[wgApxlGCLLPODtrJG94Z8NwIcm8biG7y02pf5iJ9Desu/b/jZZ0QlwZK+z5FiYlajZrWvrhu9ALy7AqUrlKG4w==], x-fb-request-id=[A4UYjL_IZGBq6kAwEMbPwNJ], x-fb-rev=[1006949215], x-fb-trace-id=[AB9UoUQSevp]}
2023-02-11 13:30:19.969 FINE: Server returned content: application/json; charset=UTF-8 of length: 136. Not printing.
2023-02-11 13:30:19.969 FINE: Downloading data...
2023-02-11 13:30:19.971 INFO: Mapillary: Failed to login: {"error":{"message":"The parameter grant_type is required.","type":"MLYApiException","code":100,"fbtrace_id":"A4UYjL_IZGBq6kAwEMbPwNJ"}}

Relative:URL: ^/trunk
Repository:UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
Last:Changed Date: 2023-01-29 21:53:34 +0100 (Sun, 29 Jan 2023)
Revision:18646
Build-Date:2023-01-30 02:30:56
URL:https://josm.openstreetmap.de/svn/trunk

Identification: JOSM/1.5 (18646 en) Linux Arch Linux
Memory Usage: 900 MB / 3912 MB (471 MB allocated, but free)
Java version: 19.0.2+7, N/A, OpenJDK 64-Bit Server VM
Look and Feel: com.formdev.flatlaf.FlatDarkLaf
Screen: :0.0 1920×1080 (scaling 1.00×1.00) :0.1 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
Desktop environment: i3
VM arguments: [--add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED, -Djosm.restart=true, -Dawt.useSystemAAFontSettings=gasp]
Program arguments: [--debug]

Plugins:
+ AddrInterpolation (36011)
+ Create_grid_of_ways (35976)
+ FastDraw (35978)
+ FixAddresses (36011)
+ HouseNumberTaggingTool (35951)
+ ImportImagePlugin (36013)
+ ImproveOsm (235)
+ MakeParallel (v1.1.0)
+ Mapillary (2.1.1)
+ OpeningHoursEditor (35924)
+ QuickLabel (23)
+ RoadSigns (36038)
+ SeaChart (35840)
+ ShapeTools (1250)
+ alignways (36011)
+ apache-commons (36034)
+ apache-http (35924)
+ auto_tools (81)
+ buildings_tools (36011)
+ changeset-viewer (0.0.6)
+ continuosDownload (105)
+ easypresets (1623509627)
+ editgpx (35931)
+ ejml (35924)
+ flatlaf (36036)
+ geotools (36028)
+ http2 (35921)
+ intersection (0.0.7)
+ jackson (36034)
+ jaxb (35952)
+ jna (36005)
+ jogl (1.2.3)
+ jts (36004)
+ log4j (36034)
+ measurement (35978)
+ notesolver (0.5.0)
+ opendata (36025)
+ openqa (v0.3.3)
+ photo_geotagging (35933)
+ photoadjust (36011)
+ print (35893)
+ pt_assistant (1ff2e15)
+ public_transport (36011)
+ reverter (36043)
+ shrinkwrap (v1.0.4)
+ tageditor (36011)
+ todo (30306)
+ touchscreenhelper (35893)
+ turnlanes-tagging (v0.0.5)
+ turnrestrictions (36011)
+ utilsplugin2 (36011)
+ wikipedia (605)

Tagging presets:
+ https://josm.openstreetmap.de/josmfile?page=Presets/ParkingLanes&zip=1
+ https://josm.openstreetmap.de/josmfile?page=Presets/Quick-stops&zip=1
+ https://raw.githubusercontent.com/yopaseopor/traffic_signs_preset_JOSM/master/US.zip
+ https://josm.openstreetmap.de/josmfile?page=Presets/Quick-highways&zip=1
+ https://josm.openstreetmap.de/josmfile?page=Presets/Playground_Equipment&zip=1
+ ${HOME}/Documents/Presets_Golf_Course.zip
+ https://josm.openstreetmap.de/josmfile?page=Presets/Telecom&zip=1
+ <josm.userdata>/EasyPresets.xml

Map paint styles:
- https://josm.openstreetmap.de/josmfile?page=Styles/Lane_features&zip=1
- https://josm.openstreetmap.de/josmfile?page=Styles/Enhanced_Lane_and_Road_Attributes&zip=1
- https://raw.githubusercontent.com/species/josm-preset-traffic_sign_direction/master/direction.mapcss
+ https://josm.openstreetmap.de/josmfile?page=Styles/ParkingLanes&zip=1
+ https://raw.githubusercontent.com/yopaseopor/traffic_signs_style_JOSM/master/Styles_Traffic_signs_AME.zip
+ https://josm.openstreetmap.de/josmfile?page=Styles/Sidewalks&zip=1
- https://raw.githubusercontent.com/yopaseopor/indoormap/master/indoormap-style.mapcss
- https://josm.openstreetmap.de/josmfile?page=Styles/Building_Levels_Labels&zip=1
- https://raw.githubusercontent.com/OpenSidewalks/OpenSidewalks-Schema/master/open_sidewalks.mapcss
- https://josm.openstreetmap.de/josmfile?page=Styles/SimpleBuildingTags&zip=1
- https://josm.openstreetmap.de/josmfile?page=Styles/SimpleRoofTags&zip=1
- https://josm.openstreetmap.de/josmfile?page=Styles/TreeCrownDiameter&zip=1
- https://raw.githubusercontent.com/species/josm-preset-wheelchair/master/sidewalks_kerbs.mapcss
- https://josm.openstreetmap.de/josmfile?page=Styles/PublicTransport&zip=1
- https://josm.openstreetmap.de/josmfile?page=Styles/AddressValidator&zip=1
- https://josm.openstreetmap.de/josmfile?page=Styles/PublicTransportV2&zip=1
+ https://josm.openstreetmap.de/josmfile?page=Styles/TigerReviewedNo&zip=1
+ https://josm.openstreetmap.de/josmfile?page=Styles/FixmeAndNote&zip=1

Last errors/warnings:
- 00009.022 E: java.nio.file.NoSuchFileException: ${HOME}/Documents/Presets_Golf_Course.zip
- 00009.022 E: ${HOME}/Documents/Presets_Golf_Course.zip
- 00009.028 E: Failed to locate image 'traffic_signs/US/US_W14-1.png'
- 00009.028 W:  null: Could not get presets icon traffic_signs/US/US_W14-1.png
- 00011.473 E: Failed to locate image 'bus.png'
- 00012.237 E: Failed to locate image 'traffic_signs/US/US_W14-1.png'
- 00012.238 W:  null: Could not get presets icon traffic_signs/US/US_W14-1.png
- 00012.242 E: Failed to locate image 'traffic_signs/US/US_W14-1.png'
- 00012.242 W:  noexit: Could not get presets icon traffic_signs/US/US_W14-1.png
- 00018.176 E: Invalid setting (Icon missing): org.openstreetmap.josm.plugins.fixAddresses.FixAddressesPreferences

Attachments (0)

Change History (6)

comment:1 by skyper, 2 years ago

Keywords: OAuth added

comment:2 by taylor.smock, 2 years ago

I'll probably rework the Mapillary OAuth support to use the JOSM OAuth implementation. Now that we have it.

comment:3 by taylor.smock, 2 years ago

Component: Plugin mapillaryPlugin http2
Owner: changed from taylor.smock to Don-vip

I cannot reproduce locally. Which is awesome. Looking at the code, there should be a grant_type in the body of the request. So something else is going on.

2023-02-11 13:30:19.971 INFO: Mapillary: Failed to login: {"error":{"message":"The parameter grant_type is required.","type":"MLYApiException","code":100,"fbtrace_id":"A4UYjL_IZGBq6kAwEMbPwNJ"}}

After some investigation, it looks like http2 is the problem. I'll see if I can fix that today, especially since we will probably be making the http2 HttpClient implementation the default once we move to Java 11+.

comment:4 by taylor.smock, 2 years ago

After quite a bit of investigation, it appears that the Http1Client codepaths sets application/x-www-form-urlencoded as the Content-Type if (a) we are POSTing (b) getOutputStream() is called and (c) no Content-Type header is yet set (according to really old documentation).

I ended up using https://httpbin.org/ to figure out what was actually being sent, since the debugger wasn't actually helpful (throughout the entire debug session, the Http1Client Content-Type header was application/json).

How do we want to handle this difference in behavior between Http1Client and Http2Client?

  1. Have the Mapillary plugin explicitly set the Content-Type.
  2. Add an explicit Content-Type set in Http2Client. I prefer this option, since it is a difference in behavior from Http1Client. This would be something like if ("POST".equals(getRequestMethod())) { /* Set the header */ }.
  3. Add an explicit Content-Type set in Http1Client.

Short class to reproduce (look at the logged responses):

class Scratch {
    public static void main(String[] args) throws IOException {
        Config.setPreferencesInstance(new MemoryPreferences());
        final URL url = new URL("https://httpbin.org/post");
        final byte[] body = "grant_type=authorization_code&client_id=1234code=some_random_code here".getBytes(StandardCharsets.UTF_8);
        HttpClient.setFactory(Http1Client::new);
        final Http1Client http1Client = (Http1Client) HttpClient.create(url, "POST");
        HttpClient.setFactory(Http2Client::new);
        final Http2Client http2Client = (Http2Client) HttpClient.create(url, "POST");
        http1Client.setRequestBody(body);
        http2Client.setRequestBody(body);
        //http2Client.setHeader("Content-Type", "application/x-www-form-urlencoded");
        try {
            Logging.info(http1Client.connect().fetchContent());
            Logging.info(http2Client.connect().fetchContent());
        } finally {
            http1Client.disconnect();
        }
    }
}

comment:5 by taylor.smock, 2 years ago

In 18662/josm:

Fix #22744, see #20768: Fix NPE when switching to authentication methods

The NPE occurs because the UI state and the saved preferences state does not
match. This is solved by saving the state to preferences and then reloading it.

This also fixes an issue where the http2 plugin would prevent the OAuth
workflow from working, due to differing default behaviors (see #22730).

comment:6 by taylor.smock, 23 months ago

Resolution: fixed
Status: newclosed

I've fixed the Mapillary issue in v2.1.4.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Don-vip.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.