2023-06-05 15:32:25 +00:00
|
|
|
import { Controller, Session, Req, Res, Get } from 'routing-controllers'
|
2023-05-24 21:57:08 +00:00
|
|
|
import { Request, Response } from 'express'
|
|
|
|
|
import OBPClientService from '../services/OBPClientService'
|
|
|
|
|
import OauthInjectedService from '../services/OauthInjectedService'
|
|
|
|
|
import { Service } from 'typedi'
|
|
|
|
|
import superagent from 'superagent'
|
|
|
|
|
|
|
|
|
|
@Service()
|
|
|
|
|
@Controller('/user')
|
|
|
|
|
export class UserController {
|
|
|
|
|
private obpExplorerHome = process.env.VITE_OBP_EXPLORER_HOST
|
|
|
|
|
constructor(
|
|
|
|
|
private obpClientService: OBPClientService,
|
|
|
|
|
private oauthInjectedService: OauthInjectedService
|
|
|
|
|
) {}
|
|
|
|
|
@Get('/logoff')
|
2023-06-05 15:32:25 +00:00
|
|
|
async logout(
|
|
|
|
|
@Session() session: any,
|
|
|
|
|
@Req() request: Request,
|
|
|
|
|
@Res() response: Response
|
|
|
|
|
): Response {
|
2023-05-24 21:57:08 +00:00
|
|
|
this.oauthInjectedService.requestTokenKey = undefined
|
|
|
|
|
this.oauthInjectedService.requestTokenSecret = undefined
|
2023-06-05 15:39:20 +00:00
|
|
|
session['clientConfig'] = undefined
|
2023-05-24 21:57:08 +00:00
|
|
|
response.redirect(this.obpExplorerHome)
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Get('/current')
|
2023-06-05 15:32:25 +00:00
|
|
|
async current(
|
|
|
|
|
@Session() session: any,
|
|
|
|
|
@Req() request: Request,
|
|
|
|
|
@Res() response: Response
|
|
|
|
|
): Response {
|
|
|
|
|
const oauthConfig = session['clientConfig']
|
2023-05-24 21:57:08 +00:00
|
|
|
const version = this.obpClientService.getOBPVersion()
|
2023-06-05 15:32:25 +00:00
|
|
|
return response.json(
|
|
|
|
|
await this.obpClientService.get(`/obp/${version}/users/current`, oauthConfig)
|
|
|
|
|
)
|
2023-05-24 21:57:08 +00:00
|
|
|
}
|
|
|
|
|
}
|