Swift oAuth 2.0 can't send request to get acces_token correctly

I want to use oAuth 2.0 from Openstreetmap.

  1. I go to auth_url and successfully get auth_code.
  2. I must send request to token_url for get access_token by swift.
    If i send post request with “nil” body, i get error 415. And if i send request with some body: fore example let data = Data(“1”.utf8) i get access_token successfully.
    Please, help me send request correctly.
    My code:
guard let url = URL(string: "https://www.openstreetmap.org/oauth2/token?grant_type=authorization_code&code=&redirect_uri=osmeditor:/&client_secret=&client_id=") else {return}
var request = URLRequest(url: url)
request.httpMethod = "POST"
let data = Data("1".utf8)
request.httpBody = data
let session = URLSession.shared
let task = session.dataTask(with: request, completionHandler: { data, response, _ in ...}

7 posts - 2 participants

Read full topic

Ce sujet de discussion accompagne la publication sur https://community.openstreetmap.org/t/swift-oauth-2-0-cant-send-request-to-get-acces-token-correctly/8365