Skip to content

Instantly share code, notes, and snippets.

View toughrogrammer's full-sized avatar

Juhong Jung toughrogrammer

View GitHub Profile
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#define Random0to1 ((double) rand() / (RAND_MAX)) + 1
#define ITERATION 100000000
HCOPY 000000001033
DBUFFER000033BUFEND001033LENGTH00002D
RRDREC WRREC
T0000001D1720274B1000000320232900003320074B1000003F2FEC0320160F2016
T00001D0D0100030F200A4B1000003E2000
T00003003454F46
M00000405+RDREC
M00001105+WRREC
M00002405+WRREC
E000000
def get_oauth_req_url():
params = {
'client_id': app.config.get('OAUTH_CLIENT_ID'),
'response_type': 'code',
'scope': 'god',
'next': urlparse(request.url).path
}
return "{0}/oauth/authorize?{1}".format(app.config.get('OAUTH_SERVER'), urlencode(params))
@app.route('/oauth/login', methods=['GET'])
def oauth_login():
form_data = {
'code': request.args['code'],
'redirect_uri': url_for('oauth_login', _external=True),
'grant_type': 'authorization_code',
'client_id': app.config.get('OAUTH_CLIENT_ID'),
'client_secret': app.config.get('OAUTH_CLIENT_SECRET'),
'scope': 'god'
}
@oauth_provider.invalid_response
def invalid_response(req):
if req.error_message == 'Bearer token is expired.':
raise ExpiredError
elif req.error_message == 'Bearer token scope not valid.':
raise NoPermissionError
else:
raise RequiredSignInError
try:
auth = OAuth(access_token) if use_auth else None
payload_data = json.dumps(payload) if payload is not None else None
if payload_data is None:
request = requests.Request(method, url, params=params, auth=auth).prepare()
else:
request = requests.Request(method, url, params=params, data=payload_data, auth=auth).prepare()
request.headers['Content-Type'] = 'application/json'
@app.errorhandler(401)
def unauthorized(e):
# 토큰이 만료된 경우에는 일단 토큰 재발급을 시도해본다
if e.description == 'expired':
return refreshing_oauth_token()
elif e.description == 'permission_required':
return render_template('error/error.html',
data={
'title': '401!!',
'header': '권한이 없어요!',
def refreshing_oauth_token():
form_data = {
'grant_type': 'refresh_token',
'client_id': app.config.get('OAUTH_CLIENT_ID'),
'client_secret': app.config.get('OAUTH_CLIENT_SECRET'),
'refresh_token': REFRESH_TOKEN
}
response = RequestOauth.get_token(form_data)
from app import api_root
from flask_restful import Resource
@api_root.resource('/documents')
class DocumentListAPI(Resource):
def get(self):
items = [
{'id': 1, 'title': 'title1', 'content': 'content1', 'ip': '1.2.3.4'},
{'id': 2, 'title': 'title2', 'content': 'content2', 'ip': '5.6.7.8'},
from app import api_root
from flask_restful import Resource
@api_root.resource('/documents')
class DocumentListAPI(Resource):
def get(self):
items = [
{'id': 1, 'title': 'title1', 'content': 'content1', 'ip': '1.2.3.4'},
{'id': 2, 'title': 'title2', 'content': 'content2', 'ip': '5.6.7.8'},