Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 207f283

Browse files
committed
Merging auth0-py example.
2 parents 72b80e5 + 741dbe4 commit 207f283

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed

examples/webapi2/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
auth0env
2+
*.pyc

examples/webapi2/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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.

examples/webapi2/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Auth0 Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, 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,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

examples/webapi2/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
##auth0-py
2+
3+
Example of integrating Auth0 with a Python Web App.
4+
5+
## Install
6+
7+
### Getting virtualenv
8+
9+
Install virtualenv (this step can be done using `easy_install` too):
10+
11+
```sh
12+
pip install virtualenv
13+
```
14+
15+
Create an environment:
16+
17+
```sh
18+
virtualenv auth0env
19+
```
20+
21+
### Installing dependencies
22+
23+
Activate your virtualenv environment:
24+
25+
```sh
26+
source auth0env/bin/activate
27+
```
28+
29+
Install dependencies:
30+
31+
```sh
32+
pip install webob webapp2 paste
33+
```
34+
35+
## Usage
36+
37+
Run the sample app:
38+
```sh
39+
python sample.py
40+
```
41+
42+
## What is Auth0?
43+
44+
Auth0 helps you to:
45+
46+
* Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others**, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
47+
* Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
48+
* Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
49+
* Support for generating signed [Json Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely.
50+
* Analytics of how, when and where users are logging in.
51+
* Pull data from other sources and add it to the user profile, through [JavaScript rules](https://docs.auth0.com/rules).
52+
53+
## Create a free account in Auth0
54+
55+
1. Go to [Auth0](https://auth0.com) and click Sign Up.
56+
2. Use Google, GitHub or Microsoft Account to login.
57+

examples/webapi2/sample.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import webapp2
2+
import urllib2
3+
import urllib
4+
import json
5+
6+
## CHANGE THIS
7+
PORT = 3000
8+
CLIENT_ID = "YOUR_CLIENT_ID"
9+
CLIENT_SECRET = "YOUR_CLIENT_SECRET"
10+
DOMAIN = "your-domain.auth0.com"
11+
CALLBACK_URL = "http://localhost:%d/callback" % PORT
12+
13+
MAIN_PAGE_HTML = """\
14+
<html>
15+
<body>
16+
<script src="https://cdn.auth0.com/w2/auth0-widget-3.0.min.js"></script>
17+
<script type="text/javascript">
18+
19+
var widget = new Auth0Widget({
20+
domain: '%s',
21+
clientID: '%s',
22+
callbackURL: '%s'
23+
});
24+
25+
</script>
26+
<button onclick="widget.signin()">Login</button>
27+
</body>
28+
</html>
29+
""" % (DOMAIN, CLIENT_ID, CALLBACK_URL)
30+
31+
class MainPage(webapp2.RequestHandler):
32+
33+
def get(self):
34+
self.response.write(MAIN_PAGE_HTML)
35+
36+
class LoginCallback(webapp2.RequestHandler):
37+
38+
def get(self):
39+
code = self.request.get("code")
40+
base_url = "https://{domain}".format(domain=DOMAIN)
41+
data = urllib.urlencode([('client_id', CLIENT_ID),
42+
('redirect_uri', CALLBACK_URL),
43+
('client_secret', CLIENT_SECRET),
44+
('code', code),
45+
('grant_type', 'authorization_code')])
46+
req = urllib2.Request(base_url + "/oauth/token", data)
47+
response = urllib2.urlopen(req)
48+
oauth = json.loads(response.read())
49+
userinfo = base_url + "/userinfo?access_token=" + oauth['access_token']
50+
51+
response = urllib2.urlopen(userinfo)
52+
data = response.read()
53+
54+
## print user data
55+
self.response.write(data)
56+
57+
58+
application = webapp2.WSGIApplication([
59+
('/', MainPage),
60+
('/callback', LoginCallback)
61+
], debug=True)
62+
63+
def main():
64+
from paste import httpserver
65+
httpserver.serve(application, host='127.0.0.1', port=PORT)
66+
67+
if __name__ == '__main__':
68+
main()
69+

0 commit comments

Comments
 (0)