Created
January 23, 2024 10:21
-
-
Save pnorman/19c103add9fcc6b9ee8a5792d2598ef4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from requests_oauthlib import OAuth2Session | |
client_id = r'0IrEz7VIm6zis60pP1jKW5ZXdLpVP0yojuG8Hy45z1o' | |
client_secret = r'Iejv415Rd-E0YqY2knXOrL8a1cmnJ-LtKMxPdmuvkyI' | |
redirect_uri = 'urn:ietf:wg:oauth:2.0:oob' | |
scope = ["read_prefs"] | |
oauth = OAuth2Session(client_id=client_id, redirect_uri=redirect_uri, scope=scope) | |
authorization_url, state = oauth.authorization_url('https://www.openstreetmap.org/oauth2/authorize') | |
print(f"Visit {authorization_url} and paste the code in") | |
code = input() | |
token = oauth.fetch_token('https://www.openstreetmap.org/oauth2/token', | |
code=code, | |
client_secret=client_secret) | |
print(token) | |
# save the token in a file somewhere or something | |
prefs = oauth.request(method='GET',url='https://www.openstreetmap.org/api/0.6/user/preferences') | |
print(prefs.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./auth_example.py | |
Visit https://www.openstreetmap.org/oauth2/authorize?response_type=code&client_id=0IrEz7VIm6zis60pP1jKW5ZXdLpVP0yojuG8Hy45z1o&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=read_prefs&state=vlG4PUbPTexvFFc9Z31oscxFcs5gN2 and paste the code in | |
oue_9LNZLk-OqS46GRjUMPZrAWi04kbapo26y5SSJ_g | |
{'access_token': 'DIdA2CDA-0pe6rysQLGlHx1tux_42V3lg3MELhoKseE', 'token_type': 'Bearer', 'scope': ['read_prefs'], 'created_at': 1706004195} | |
<?xml version="1.0" encoding="UTF-8"?> | |
<osm version="0.6" generator="OpenStreetMap server" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/"> | |
<preferences> | |
<preference k="diary.default_language" v="en"/> | |
<preference k="gps.trace.visibility" v="identifiable"/> | |
</preferences> | |
</osm> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment