oAuth 2.0 can not get access_token

Hello.
I make personal iOS app for editing Openstreetmap. I want log in with oAuth 2.0
My user go to auth page /oauth2/authorize
Enter login and pass, and after redirect i have code=CODE
Than i need send secret_key and this code to url https://www.openstreetmap.org/oauth2/token/
for example:
/oauth2/token/?code=CODE&secret_key=SECRET_KEY
But i have error 404

How can i fix it? Thank you

You need to POST to that endpoint, there is no GET route for it.

Yes that should ideally be 405 Method Not Allowed not 404 Not Found but due to the way rails works it treats the method as part of the route…

i must send post request? What data i must send? JSON or XML? What headers?
In wiki i don’t read it

I have no idea what’s in the wiki, but yes you need to send a POST request with whatever parameters the OAuth flow you are using requires. That probably means:

  • client_id - your client’s ID
  • client_secret - your client’s secret
  • code - the authorization code the server returned
  • code_verifier - your verifier value if you’re using PKCE (which you should be if your secret is shared at all)
  • grant_type - should be authorization_code
  • redirect_uri - where to redirect to

thank you, i’ll try

i send POST request:
data = nil,
headers:
{“client_id”:“CLIENT_ID”,
“redirect_uri”:“osmeditor:/”,
“code”:“CODE”,
“grant_type”:“authorization_code”,
“client_secret”:“CLIENT_SECRET”}

and i get error 415 - The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format.

I understand how it work.
I must send POST request:
data = {“client_id”:“CLIENT_ID”,
“redirect_uri”:“osmeditor:/”,
“code”:“CODE”,
“grant_type”:“authorization_code”,
“client_secret”:“CLIENT_SECRET”}

headers = nil

Than we get JSON with access_token