|
@@ -64,53 +64,55 @@ class AuthView(View):
|
|
|
client_id = request_dict.get("client_id", '')
|
|
|
response_type = request_dict.get("response_type", '')
|
|
|
scope = request_dict.get("scope", '')
|
|
|
- app_id = request_dict.get("app_id", '')
|
|
|
+ app_id = request_dict.get("appBundleId", '')
|
|
|
redirect_uri = request_dict.get("redirect_uri", '')
|
|
|
- client_secret = request_dict.get("client_secret", '')
|
|
|
token = request_dict.get('token', None)
|
|
|
# print("client_id", client_id)
|
|
|
# print("state", state)
|
|
|
# print("response_type", response_type)
|
|
|
# print("scope", scope)
|
|
|
# print("redirect_uri", redirect_uri)
|
|
|
- # print("client_secret", client_secret)
|
|
|
tko = TokenObject(token)
|
|
|
if tko.code == 0:
|
|
|
userID = tko.userID
|
|
|
nowTime = int(time.time())
|
|
|
user_qs = GrantCodeModel.objects.filter(userID__userID=userID)
|
|
|
code = CommonService.encrypt_data(randomlength=32)
|
|
|
- application = ApplicationModel.objects.filter(client_id=client_id)
|
|
|
-
|
|
|
- if application.exists():
|
|
|
- print(application.exists())
|
|
|
+ if client_id == '':
|
|
|
+ application = ApplicationModel.objects.filter(grant_type="authorization_code")
|
|
|
else:
|
|
|
- return response.json(10005)
|
|
|
-
|
|
|
- if application[0].redirect_uri != redirect_uri:
|
|
|
- return response.json(10006)
|
|
|
+ application = ApplicationModel.objects.filter(client_id=client_id)
|
|
|
+ if application.exists():
|
|
|
+ print(application.exists())
|
|
|
+ else:
|
|
|
+ return response.json(10005)
|
|
|
|
|
|
+ if redirect_uri == '':
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ if application[0].redirect_uri != redirect_uri:
|
|
|
+ return response.json(10006)
|
|
|
if not user_qs.exists():
|
|
|
print('在创建')
|
|
|
try:
|
|
|
grantcode = GrantCodeModel(
|
|
|
userID=Device_User.objects.get(userID=userID),
|
|
|
- application=ApplicationModel.objects.get(client_id=client_id),
|
|
|
+ application=application,
|
|
|
code=code,
|
|
|
app_id=app_id,
|
|
|
expire_time=nowTime+3600,
|
|
|
add_time=nowTime,
|
|
|
update_time=nowTime)
|
|
|
grantcode.save()
|
|
|
-
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
return response.json(178)
|
|
|
else:
|
|
|
print('在修改')
|
|
|
user_qs.update(code=code, app_id=app_id, update_time=nowTime, expire_time=nowTime+3600)
|
|
|
-
|
|
|
- redirect_uri = redirect_uri + '?code=' + code + '&state=' + state
|
|
|
+ if state == '':
|
|
|
+ state = CommonService.encrypt_data(randomlength=4)
|
|
|
+ redirect_uri = application[0].redirect_uri + '?code=' + code + '&state=' + state
|
|
|
if application[0].skip_auth:
|
|
|
return HttpResponseRedirect(redirect_uri)
|
|
|
return response.json(0, {'url': redirect_uri})
|