amity/app/token.py
Micke Nordin 4dd92c0bdc
first commit
Signed-off-by: Micke Nordin <kano@sunet.se>
2025-06-24 13:27:40 +02:00

36 lines
976 B
Python

import cherrypy
import json
class Token(object):
@cherrypy.expose
@cherrypy.tools.json_out()
def index(self):
raw_body = cherrypy.request.body.read()
data = json.loads(raw_body)
client_id = data['client_id']
code = data['code']
grant_type = data['grant_type']
if grant_type == 'ocm_authorization_code':
return self.get_token(client_id, code)
else:
return {'error': 'unsupported grant_type'}
def get_token(self, client_id, code) -> dict:
if self.validate_token(client_id, code):
token = {
"access_token": "asdfgh",
"token_type": "bearer",
"expires_in": 3600,
"refresh_token": "qwertyuiop"
}
return token
else:
error = {'error': 'invalid_grant'}
return error
def validate_token(self, client_id, token) -> bool:
return True