Skip to content

Commit

Permalink
Merge pull request #55 from SEbbaDK/server-reenable-auth
Browse files Browse the repository at this point in the history
server: Reenable auth
  • Loading branch information
SEbbaDK committed May 27, 2021
2 parents 87ece54 + 3c9f9af commit 5ce31ec
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions server/src/maptogether-server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,19 @@ module MapTogether::Server
# TODO: It is important that we add this check back in, but oauth seems to be broken
# with osm, so it is disabled for now

# client = HTTP::Client.new "master.apis.dev.openstreetmap.org", tls: true
# OAuth.authenticate client, key, secret, ckey, csecret

# response = client.get("/api/0.6/user/details.json")
# puts vals if response.status_code != 200
# puts "Body: #{response.body}" if response.status_code != 200
# http_raise 401, "Authentication failed for OSM" if response.status_code == 401
# http_raise 500, "Something went wrong with OSM login: #{response.status_code} #{response.body}" if response.status_code != 200
# json = JSON.parse(response.body)
# osm_id = json["user"]["id"].as_i64
# name = json["user"]["display_name"]

# TEMP
name = "User #{id}"
# TEMP

# http_raise 400, "Id: #{id} does not match the OSM id of #{osm_id}" if id != osm_id
client = HTTP::Client.new "master.apis.dev.openstreetmap.org", tls: true
OAuth.authenticate client, key, secret, ckey, csecret

response = client.get("/api/0.6/user/details.json")
puts vals if response.status_code != 200
puts "Body: #{response.body}" if response.status_code != 200
http_raise 401, "Authentication failed for OSM" if response.status_code == 401
http_raise 500, "Something went wrong with OSM login: #{response.status_code} #{response.body}" if response.status_code != 200
json = JSON.parse(response.body)
osm_id = json["user"]["id"].as_i64
name = json["user"]["display_name"]

http_raise 400, "Id: #{id} does not match the OSM id of #{osm_id}" if id != osm_id

POOL.using_connection do |db|
puts "Upserting user"
Expand Down

0 comments on commit 5ce31ec

Please sign in to comment.