Commit bf8e0b949c0a48f06eae8f3d01a4618957b6d229
- Diff rendering mode:
- inline
- side by side
swtr/sampleConf.py
(0 / 4)
  | |||
1 | HOST='http://127.0.0.1' | ||
2 | PORT=5000 | ||
3 | swtstoreURL='http://sweet/store/url' | ||
4 | debug=True |
swtr/sample_config.py
(12 / 0)
  | |||
1 | # the URL pointing to the sweet store this application will sweet to | ||
2 | swtstoreURL = 'http://sweet/store/url' | ||
3 | # the app_id or client_id you have recieved when you registered this | ||
4 | # application to swtstore | ||
5 | app_id = 'the app_id or client_id' | ||
6 | # the app_secret or client_secret you have recieved when you registered this | ||
7 | # application to swtstore | ||
8 | app_secret = 'the app_secret or client_secret' | ||
9 | # the URL at which your application is hosted | ||
10 | # when you are deploying the app locally, by default this should be | ||
11 | #redirect_uri = 'http://localhost:5000' | ||
12 | redirect_uri = 'http://yourapplication.domain' |
swtr/server.py
(18 / 16)
  | |||
2 | 2 | ||
3 | 3 | import flask | |
4 | 4 | from flask import session | |
5 | import conf | ||
5 | import config | ||
6 | 6 | import requests | |
7 | 7 | import json | |
8 | 8 | ||
9 | 9 | app = flask.Flask(__name__) | |
10 | app.config['SECRET_KEY'] = config.secret_key | ||
10 | 11 | ||
11 | app.config['secret_key'] = "asdkasdiq2jedmaid0q2238uwadscksnc" | ||
12 | app.secret_key = "asdkasdiq2jedmaid0q2238uwadscksnc" | ||
13 | 12 | ||
14 | appID = 'YrYc9oMO7fT0avRUAtbRO1cLvoOUUI08BAuqOAJc' | ||
15 | appSecret = 'r9BIYjYOPotMQUOoI98DmH7Eu1M4zg6cMeLay7LOlSsrF1KhKZ' | ||
16 | |||
17 | 13 | @app.route('/', methods=['GET']) | |
18 | 14 | def index(): | |
19 | 15 | auth_tok = None | |
20 | 16 | if flask.request.args.get('code'): | |
21 | 17 | payload = { | |
22 | 18 | 'scopes': 'email sweet', | |
23 | 'client_secret': appSecret, | ||
19 | 'client_secret': config.app_secret, | ||
24 | 20 | 'code': flask.request.args.get('code'), | |
25 | 'redirect_uri': 'http://localhost:5000/', | ||
21 | 'redirect_uri': config.redirect_uri, | ||
26 | 22 | 'grant_type': 'authorization_code', | |
27 | 'client_id': appID | ||
23 | 'client_id': config.app_id | ||
28 | 24 | } | |
29 | resp = requests.post('http://localhost:5001/oauth/token', data=payload) | ||
25 | # token exchange endpoint | ||
26 | oauth_token_x_endpoint = config.swtstoreURL + '/oauth/token' | ||
27 | resp = requests.post(oauth_token_x_endpoint, data=payload) | ||
30 | 28 | auth_tok = json.loads(resp.text) | |
31 | 29 | print auth_tok | |
32 | if auth_tok.has_key('error'): | ||
30 | |||
31 | if 'error' in auth_tok: | ||
33 | 32 | print auth_tok['error'] | |
34 | 33 | return flask.make_response(auth_tok['error'], 200) | |
35 | 34 | ||
… | … | ||
41 | 41 | ||
42 | 42 | print auth_tok | |
43 | 43 | return flask.render_template('index.html', | |
44 | access_token=auth_tok['access_token'], | ||
45 | refresh_token=auth_tok['refresh_token'], | ||
46 | url=flask.request.args.get('where'), | ||
47 | conf=conf) | ||
44 | access_token=auth_tok['access_token'], | ||
45 | refresh_token=auth_tok['refresh_token'], | ||
46 | config=config, | ||
47 | url=flask.request.args.get('where')) | ||
48 | 48 | ||
49 | |||
50 | # if the app is run directly from command-line | ||
51 | # assume its being run locally in a dev environment | ||
49 | 52 | if __name__ == '__main__': | |
50 | app.run(debug=conf.debug, host=conf.HOST, port=conf.PORT) | ||
53 | app.run(debug=True, host='0.0.0.0', port=5000) |
swtr/static/js/swtmaker.js
(9 / 6)
  | |||
23 | 23 | if(swtr.access_token) { | |
24 | 24 | $('#signinview').html('Signing you in..'); | |
25 | 25 | $.ajax({ | |
26 | url: 'http://localhost:5001/api/users/me?access_token='+ | ||
26 | url: swtr.swtstoreURL()+'/api/users/me?access_token='+ | ||
27 | 27 | swtr.access_token, | |
28 | 28 | success: function(data) { | |
29 | console.log(data.username); | ||
29 | 30 | swtr.appView.userLoggedIn(data.username); | |
31 | }, | ||
32 | error: function() { | ||
33 | $('#signinview').html('Error signing in! Please try again'); | ||
30 | 34 | } | |
31 | 35 | }); | |
32 | 36 | } | |
… | … | ||
236 | 236 | } | |
237 | 237 | ||
238 | 238 | this.oauth = new Oauth({ | |
239 | app_id: 'YrYc9oMO7fT0avRUAtbRO1cLvoOUUI08BAuqOAJc', | ||
240 | app_secret: 'r9BIYjYOPotMQUOoI98DmH7Eu1M4zg6cMeLay7LOlSsrF1KhKZ', | ||
241 | endpoint: 'http://localhost:5001/oauth/authorize', | ||
242 | redirect_uri: 'http://localhost:5000/', | ||
239 | app_id: swtr.app_id, | ||
240 | app_secret: swtr.app_secret, | ||
241 | endpoint: swtr.swtstoreURL() + swtr.endpoints.auth, | ||
242 | redirect_uri: swtr.oauth_redirect_uri, | ||
243 | 243 | scopes: 'email,sweet' | |
244 | 244 | }); | |
245 | 245 | }, | |
… | … | ||
339 | 339 | $('#signin-msg').html('Error signing in. Please check your username and password. '); | |
340 | 340 | } | |
341 | 341 | else { | |
342 | $('#signin-msg').html('Error signin in. Please try again. '); | ||
343 | 342 | } | |
344 | 343 | } | |
345 | 344 | }); |
swtr/templates/index.html
(11 / 3)
  | |||
51 | 51 | ||
52 | 52 | <script> | |
53 | 53 | window.swtr = window.swtr || {}; | |
54 | swtr.swtstoreURL = function() { return '{{ conf.swtstoreURL }}'; } | ||
55 | swtr.endpoints = {'get': '/api/sweets/q', 'post': '/api/sweets', 'auth': | ||
56 | '/authenticate', 'login': '/auth/login', 'logout': '/auth/logout'}; | ||
54 | swtr.swtstoreURL = function() { return '{{ config.swtstoreURL }}'; } | ||
55 | swtr.endpoints = { | ||
56 | 'get': '/api/sweets/q', | ||
57 | 'post': '/api/sweets', | ||
58 | 'auth': '/oauth/authorize', | ||
59 | 'login': '/auth/login', | ||
60 | 'logout': '/auth/logout' | ||
61 | }; | ||
57 | 62 | swtr.access_token = '{{ access_token }}'; | |
58 | 63 | swtr.refresh_token = '{{ refresh_token }}'; | |
64 | swtr.app_id = '{{ config.app_id }}'; | ||
65 | swtr.app_secret = '{{ config.app_secret }}'; | ||
66 | swtr.oauth_redirect_uri = '{{ config.redirect_uri }}'; | ||
59 | 67 | window.onload = function() { | |
60 | 68 | swtr.init(); | |
61 | 69 | }; |