mirror of
https://github.com/OpenBankProject/API-Explorer-II.git
synced 2026-02-06 10:47:04 +00:00
integration WIP
This commit is contained in:
parent
1ca686b892
commit
0feb271e23
@ -58,22 +58,22 @@ export class OpeyController {
|
||||
console.log("Getting consent from OBP")
|
||||
// Check if consent is already in session
|
||||
if (session['obpConsent']) {
|
||||
console.log("Consent found in session, returning cached consent")
|
||||
console.log("Consent found in session, returning cached consent ID")
|
||||
const obpConsent = session['obpConsent']
|
||||
// NOTE: Arguably we should not return the consent to the frontend as it could be hijacked,
|
||||
// we can keep everything in the backend and only return the JWT token
|
||||
return response.status(200).json(true);
|
||||
return response.status(200).json({consent_id: obpConsent.consent_id});
|
||||
}
|
||||
|
||||
const oauthConfig = session['clientConfig']
|
||||
const version = this.obpClientService.getOBPVersion()
|
||||
// Obbiously this should not be hard-coded, especially the consumer_id, but for now it is
|
||||
const consentBody = {
|
||||
const consentRequestBody = {
|
||||
"everything": false,
|
||||
"views": [],
|
||||
"entitlements": [],
|
||||
"consumer_id": "33e0a1bd-9f1d-4128-911b-8936110f802f"
|
||||
}
|
||||
// 33e0a1bd-9f1d-4128-911b-8936110f802f
|
||||
|
||||
// Get current user, only proceed if user is logged in
|
||||
const currentUser = await this.obpClientService.get(`/obp/${version}/users/current`, oauthConfig)
|
||||
@ -84,12 +84,12 @@ export class OpeyController {
|
||||
|
||||
// url needs to be changed once we get the 'bankless' consent endpoint
|
||||
// this creates a consent for the current logged in user, and starts SCA flow i.e. sends SMS or email OTP to user
|
||||
const consent = await this.obpClientService.create(`/obp/${version}/banks/gh.29.uk/my/consents/IMPLICIT`, consentBody, oauthConfig)
|
||||
const consent = await this.obpClientService.create(`/obp/${version}/banks/gh.29.uk/my/consents/IMPLICIT`, consentRequestBody, oauthConfig)
|
||||
console.log("Consent: ", consent)
|
||||
|
||||
// store consent in session, return consent 200 OK
|
||||
session['obpConsent'] = consent
|
||||
return response.status(200).json(true);
|
||||
return response.status(200).json({consent_id: consent.consent_id});
|
||||
} catch (error) {
|
||||
console.error("Error in consent endpoint: ", error);
|
||||
return response.status(500).json({ error: 'Internal Server Error '});
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
<script>
|
||||
import Prism from 'prismjs';
|
||||
import MarkdownIt from "markdown-it";
|
||||
import axios from 'axios';
|
||||
import 'prismjs/themes/prism.css'; // Choose a theme you like
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { inject } from 'vue';
|
||||
@ -82,6 +83,7 @@
|
||||
awaitingConnection: !this.isConnected,
|
||||
awaitingConsentChallengeAnswer: false,
|
||||
consentChallengeAnswer: '',
|
||||
consentId: '',
|
||||
isLoading: false,
|
||||
obpApiHost: null,
|
||||
isLoggedIn: null,
|
||||
@ -118,23 +120,22 @@
|
||||
},
|
||||
async establishWebSocketConnection() {
|
||||
// Get the Opey JWT token
|
||||
let token = ''
|
||||
try {
|
||||
token = await getOpeyJWT()
|
||||
} catch (error) {
|
||||
console.log('Error creating JWT for opey: ', error)
|
||||
this.errorState = true
|
||||
ElMessage({
|
||||
message: 'Error getting Opey JWT token',
|
||||
type: 'error'
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// try to get a consent token
|
||||
try {
|
||||
token = await getOpeyConsent()
|
||||
this.awaitingConsentChallengeAnswer = true
|
||||
const consentResponse = await getOpeyConsent()
|
||||
console.log('Consent response: ', consentResponse)
|
||||
if (consentResponse.status === 200 && consentResponse.data.consent_id) {
|
||||
this.consentId = consentResponse.data.consent_id
|
||||
this.awaitingConsentChallengeAnswer = true
|
||||
} else {
|
||||
console.log('Error getting consent for opey from OBP: ', consentResponse)
|
||||
this.errorState = true
|
||||
ElMessage({
|
||||
message: 'Error getting consent for opey from OBP',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log('Error getting consent for opey from OBP: ', error)
|
||||
this.errorState = true
|
||||
@ -144,19 +145,6 @@
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Establish the WebSocket connection
|
||||
console.log('Establishing WebSocket connection');
|
||||
try{
|
||||
this.connectionStore.connect(token)
|
||||
} catch (error) {
|
||||
console.log('Error establishing WebSocket connection: ', error)
|
||||
this.errorState = true
|
||||
ElMessage({
|
||||
message: 'Error establishing WebSocket connection',
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
async answerConsentChallenge() {
|
||||
@ -167,10 +155,23 @@
|
||||
}
|
||||
|
||||
try {
|
||||
const answerBody = {
|
||||
answer: challengeAnswer
|
||||
}
|
||||
const response = await answerOpeyConsentChallenge(answerBody)
|
||||
console.log(`Answering consent challenge with: ${challengeAnswer} and consent_id: ${this.consentId}`)
|
||||
|
||||
|
||||
// send the challenge answer to Opey for approval
|
||||
const response = await axios.post(
|
||||
`${this.chatBotUrl}/auth`,
|
||||
JSON.stringify({"consent_id": this.consentId, "consent_challenge_answer": challengeAnswer}),
|
||||
{
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
withCredentials: true,
|
||||
}
|
||||
)
|
||||
|
||||
console.log("Consent challenge response: ", response.status, response.headers)
|
||||
if (response.status === 200) {
|
||||
console.log('Consent challenge answered successfully, Consent approved')
|
||||
this.awaitingConsentChallengeAnswer = false
|
||||
|
||||
@ -93,8 +93,7 @@ export async function getOpeyConsent() {
|
||||
throw new Error(`getOpeyConsent returned an error: ${error.message}`);
|
||||
}
|
||||
});
|
||||
const consent = String(response?.data?.consent)
|
||||
return consent
|
||||
return response
|
||||
}
|
||||
|
||||
export async function answerOpeyConsentChallenge(answerBody: any) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user