Skip to content

Instantly share code, notes, and snippets.

@KalanaDananjaya
Created August 23, 2022 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KalanaDananjaya/45bf9a8db860473752c480556a0c508d to your computer and use it in GitHub Desktop.
Save KalanaDananjaya/45bf9a8db860473752c480556a0c508d to your computer and use it in GitHub Desktop.
CIBA - Automated Approval Endpoint
from flask import Flask,jsonify,make_response, request
import json
from flask import Response
import mysql.connector
import os
ASSETS_DIR = os.path.dirname(os.path.abspath(__file__))
app = Flask('app')
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="openbank_apimgtdb_conformance"
)
mycursor = mydb.cursor()
@app.route('/automatedapproval', methods=["GET","POST"])
def automatedapproval():
body = {}
args = request.args
action = args.get("action")
if (action == "allow"):
action = "AUTHENTICATED"
if (action=="deny"):
action = "CONSENT_DENIED"
auth_req_id = args.get("token")
query = "UPDATE IDN_OAUTH2_CIBA_AUTH_CODE SET AUTH_REQ_STATUS = '{action}', AUTHENTICATED_USER_NAME='admin@wso2.com', USER_STORE_DOMAIN='abc', TENANT_ID = 1, IDP_ID = 1 WHERE AUTH_REQ_ID = '{token}'".format(action = action, token = auth_req_id)
print(query)
mycursor.execute(query)
mydb.commit()
response = make_response(jsonify(body))
response.headers['content-type'] = 'application/json'
return response
context = ('cert.pem', 'key.pem')
app.run(host = '0.0.0.0', port = 9000, ssl_context=context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment