204 |
204 |
205 |
205 |
206 @app.route('/oauth/oauth2/authorize', methods=['GET', 'POST']) |
206 @app.route('/oauth/oauth2/authorize', methods=['GET', 'POST']) |
207 @oauth.authorize_handler |
207 @oauth.authorize_handler |
208 def authorize(*args, **kwargs): |
208 def authorize(*args, **kwargs): |
209 print(request.headers) |
|
210 user = current_user() |
209 user = current_user() |
211 if not user: |
210 if not user: |
212 return redirect('/') |
211 return redirect('/') |
213 if request.method == 'GET': |
212 if request.method == 'GET': |
214 client_id = kwargs.get('client_id') |
213 client_id = kwargs.get('client_id') |
227 user = request.oauth.user |
226 user = request.oauth.user |
228 return jsonify(id=user.id, username=user.username) |
227 return jsonify(id=user.id, username=user.username) |
229 |
228 |
230 @app.route('/rest/oauth/validate/<token>') |
229 @app.route('/rest/oauth/validate/<token>') |
231 def validate_token(token): |
230 def validate_token(token): |
232 print(request.headers) |
|
233 database_token = Token.query.filter_by(access_token=token).first() |
231 database_token = Token.query.filter_by(access_token=token).first() |
234 related_client = database_token.client |
232 related_client = database_token.client |
235 return jsonify( |
233 return jsonify( |
236 access_token=token, |
234 access_token=token, |
237 redirect_uri= related_client.redirect_uris, |
235 redirect_uri= related_client.redirect_uris, |
238 error=0, |
236 error=0, |
239 description= "", |
237 description= "", |
240 scope=database_token.scopes |
238 scope=database_token.scopes |
241 ) |
239 ) |
242 |
240 |
|
241 @app.route('/ws/resource/<resource_id>', methods=["POST", "PUT"]) |
|
242 @oauth.require_oauth() |
|
243 def reference_resource(resource_id): |
|
244 print("#########################") |
|
245 print(request.headers) |
|
246 print("#########################") |
|
247 print(request.data) |
|
248 return "Resource was referenced", 200 |
|
249 |
243 def init_client(client_id, client_secret, redirect_uris, client_owner, confidential=False): |
250 def init_client(client_id, client_secret, redirect_uris, client_owner, confidential=False): |
244 client = Client.query.filter_by(client_id=client_id, client_secret=client_secret).first() |
251 client = Client.query.filter_by(client_id=client_id, client_secret=client_secret).first() |
245 if not client: |
252 if not client: |
246 print("Creating client for "+client_owner) |
253 print("Creating client for "+client_owner) |
247 user = User.query.filter_by(username=client_owner).first() |
254 user = User.query.filter_by(username=client_owner).first() |
248 if not user: |
255 if not user: |
249 user = User(username=username) |
256 user = User(username=client_owner) |
250 db.session.add(user) |
257 db.session.add(user) |
251 db.session.commit() |
258 db.session.commit() |
252 if confidential: |
259 if confidential: |
253 type="confidential" |
260 type="confidential" |
254 else: |
261 else: |
268 db.create_all() |
275 db.create_all() |
269 init_client( |
276 init_client( |
270 client_id=app.config["RENKAN_CLIENT_ID"], |
277 client_id=app.config["RENKAN_CLIENT_ID"], |
271 client_secret=app.config["RENKAN_CLIENT_SECRET"], |
278 client_secret=app.config["RENKAN_CLIENT_SECRET"], |
272 redirect_uris=app.config["RENKAN_REDIRECT_URIS"], |
279 redirect_uris=app.config["RENKAN_REDIRECT_URIS"], |
273 client_owner=app.config["RENKAN_SERVER_USER"] |
280 client_owner=app.config["RENKAN_SERVER_USER"], |
|
281 confidential=True |
274 ) |
282 ) |
275 init_client( |
283 init_client( |
276 client_id=app.config["MOCK_GED_CLIENT_ID"], |
284 client_id=app.config["MOCK_GED_CLIENT_ID"], |
277 client_secret=app.config["MOCK_GED_CLIENT_SECRET"], |
285 client_secret=app.config["MOCK_GED_CLIENT_SECRET"], |
278 redirect_uris=app.config["MOCK_GED_REDIRECT_URIS"], |
286 redirect_uris=app.config["MOCK_GED_REDIRECT_URIS"], |