├── README.md ├── LICENSE └── sample.py /README.md: -------------------------------------------------------------------------------- 1 | auth0-py 2 | ======== 3 | 4 | Python SDK 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Auth0 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /sample.py: -------------------------------------------------------------------------------- 1 | import webapp2 2 | import urllib2 3 | import urllib 4 | import json 5 | 6 | ## CHANGE THIS 7 | CLIENT_ID = "YOUR_CLIENT_ID" 8 | CLIENT_SECRET = "YOUR_CLIENT_SECRET" 9 | DOMAIN = "YOURS.auth0.com" 10 | CALLBACK_URL = "http://localhost:8080/callback" 11 | 12 | MAIN_PAGE_HTML = """\ 13 | 14 |
15 | 16 | 25 | 26 | 27 | 28 | """ % (DOMAIN, CLIENT_ID, CALLBACK_URL) 29 | 30 | class MainPage(webapp2.RequestHandler): 31 | 32 | def get(self): 33 | self.response.write(MAIN_PAGE_HTML) 34 | 35 | class LoginCallback(webapp2.RequestHandler): 36 | 37 | def get(self): 38 | code = self.request.get("code") 39 | base_url = "https://{domain}".format(domain=DOMAIN) 40 | data = urllib.urlencode([('client_id', CLIENT_ID), 41 | ('redirect_uri', CALLBACK_URL), 42 | ('client_secret', CLIENT_SECRET), 43 | ('code', code), 44 | ('grant_type', 'authorization_code')]) 45 | req = urllib2.Request(base_url + "/oauth/token", data) 46 | response = urllib2.urlopen(req) 47 | oauth = json.loads(response.read()) 48 | userinfo = base_url + "/userinfo?access_token=" + oauth['access_token'] 49 | 50 | response = urllib2.urlopen(userinfo) 51 | data = response.read() 52 | 53 | ## print user data 54 | self.response.write(data) 55 | 56 | 57 | application = webapp2.WSGIApplication([ 58 | ('/', MainPage), 59 | ('/callback', LoginCallback) 60 | ], debug=True) 61 | --------------------------------------------------------------------------------