Skip to content

Commit dc69f96

Browse files
committed
OAuth2 login first step works
1 parent d14fb57 commit dc69f96

File tree

8 files changed

+395
-388
lines changed

8 files changed

+395
-388
lines changed

server/controllers/OpeyIIController.ts

Lines changed: 334 additions & 345 deletions
Large diffs are not rendered by default.

server/controllers/RequestController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@
2828
import { Controller, Session, Req, Res, Get, Delete, Post, Put } from 'routing-controllers'
2929
import { Request, Response } from 'express'
3030
import OBPClientService from '../services/OBPClientService'
31-
import { Service } from 'typedi'
31+
import { Service, Container } from 'typedi'
3232

3333
@Service()
3434
@Controller()
3535
export class OBPController {
36-
constructor(private obpClientService: OBPClientService) {}
36+
private obpClientService: OBPClientService
37+
38+
constructor() {
39+
// Explicitly get OBPClientService from the container to avoid injection issues
40+
this.obpClientService = Container.get(OBPClientService)
41+
}
42+
3743
@Get('/get')
3844
async get(@Session() session: any, @Req() request: Request, @Res() response: Response): Response {
3945
const path = request.query.path

server/controllers/StatusController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { Controller, Session, Req, Res, Get } from 'routing-controllers'
2929
import { Request, Response } from 'express'
3030
import OBPClientService from '../services/OBPClientService'
3131

32-
import { Service } from 'typedi'
32+
import { Service, Container } from 'typedi'
3333
import { OAuthConfig } from 'obp-typescript'
3434
import { commitId } from '../app'
3535

@@ -43,7 +43,13 @@ export class StatusController {
4343
'stored_procedure_vDec2019',
4444
'rabbitmq_vOct2024'
4545
]
46-
constructor(private obpClientService: OBPClientService) {}
46+
private obpClientService: OBPClientService
47+
48+
constructor() {
49+
// Explicitly get OBPClientService from the container to avoid injection issues
50+
this.obpClientService = Container.get(OBPClientService)
51+
}
52+
4753
@Get('/')
4854
async index(
4955
@Session() session: any,

server/controllers/UserController.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@
2828
import { Controller, Session, Req, Res, Get } from 'routing-controllers'
2929
import { Request, Response } from 'express'
3030
import OBPClientService from '../services/OBPClientService'
31-
import { Service } from 'typedi'
31+
import { Service, Container } from 'typedi'
3232
import { OAuth2Service } from '../services/OAuth2Service'
3333

3434
@Service()
3535
@Controller('/user')
3636
export class UserController {
3737
private obpExplorerHome = process.env.VITE_OBP_API_EXPLORER_HOST
38+
private obpClientService: OBPClientService
39+
private oauth2Service: OAuth2Service
40+
41+
constructor() {
42+
// Explicitly get services from the container to avoid injection issues
43+
this.obpClientService = Container.get(OBPClientService)
44+
this.oauth2Service = Container.get(OAuth2Service)
45+
}
3846

39-
constructor(
40-
private obpClientService: OBPClientService,
41-
private oauth2Service: OAuth2Service
42-
) {}
4347
@Get('/logoff')
4448
async logout(
4549
@Session() session: any,

shared-constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DEFAULT_OBP_API_VERSION is used in case the environment variable VITE_OBP_API_VERSION is not set
2+
export const DEFAULT_OBP_API_VERSION = 'v6.0.0'

src/components/ChatWidget.vue

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
placeholder for Opey II Chat widget
3-
-->
3+
-->
44
<script lang="ts">
55
66
import { ref, reactive } from 'vue'
@@ -14,7 +14,7 @@ import { useChat } from '@/stores/chat';
1414
1515
export default {
1616
setup () {
17-
return {
17+
return {
1818
Close,
1919
ElTop,
2020
WarnTriangleFilled,
@@ -36,7 +36,7 @@ export default {
3636
this.chat = useChat()
3737
const isLoggedIn = await this.checkLoginStatus()
3838
console.log('Is logged in: ', isLoggedIn)
39-
39+
4040
},
4141
methods: {
4242
async toggleChat() {
@@ -55,14 +55,14 @@ export default {
5555
this.errorState.message = "Woops! Looks like we are having trouble connecting to Opey..."
5656
this.errorState.icon = WarnTriangleFilled
5757
}
58-
58+
5959
}
6060
return true
6161
} else {
6262
return false
6363
}
6464
},
65-
65+
6666
async onSubmit() {
6767
// Add user message to the messages array
6868
const userMessage: UserMessage = {
@@ -71,7 +71,7 @@ export default {
7171
content: this.input,
7272
isToolCallApproval: false,
7373
};
74-
74+
7575
// Set status to loading // Clear input field after sending
7676
this.chat.status = 'loading';
7777
this.input = '';
@@ -80,7 +80,7 @@ export default {
8080
await this.chat.stream({
8181
message: userMessage,
8282
}
83-
83+
8484
)
8585
console.log('Opey Status: ', this.chat.status)
8686
} catch (error) {
@@ -112,11 +112,11 @@ export default {
112112
<div class="chat-container-inner" id="chat-container">
113113
<el-container direction="vertical">
114114
<el-header>
115-
<img alt="Opey Logo" src="@/assets/opey-logo-inv.png">
115+
<img alt="Opey Logo" src="@/assets/opey-logo-inv.png">
116116
<el-button type="danger" :icon="Close" @click="toggleChat" size="small" circle></el-button>
117117
</el-header>
118118
<el-main>
119-
119+
120120
<div v-if="errorState.type === 'authenticationError'" class="login-container">
121121
<el-icon :size="40" color="#FF4D4F">
122122
<component :is="errorState.icon" />
@@ -125,7 +125,7 @@ export default {
125125
</div>
126126
<div v-else-if="!chat.userIsAuthenticated" class="login-container">
127127
<p class="login-message" size="large">Opey is only available once logged on.</p>
128-
<a href="/api/connect" class="login-button router-link">Log on</a>
128+
<a href="/api/oauth2/connect" class="login-button router-link">Log on</a>
129129
</div>
130130
<div v-else class="messages-container" v-bind:class="{ disabled: !chat.userIsAuthenticated }">
131131
<el-scrollbar>
@@ -322,7 +322,7 @@ textarea::-webkit-scrollbar-thumb {
322322
323323
/* Handle on hover */
324324
textarea::-webkit-scrollbar-thumb:hover {
325-
325+
326326
background: #888;
327327
}
328328
@@ -334,4 +334,4 @@ textarea::-webkit-scrollbar-thumb:hover {
334334
.user-input-container button {
335335
margin-bottom: 0px;
336336
}
337-
</style>
337+
</style>

src/components/ChatWidgetOld.vue

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
setup() {
5555
/**
5656
* Pinia stores only work properly in the vue composition API, hence the setup() call here, which allows us to use the vue composition API within the vue options API
57-
* See https://vueschool.io/articles/vuejs-tutorials/options-api-vs-composition-api/
57+
* See https://vueschool.io/articles/vuejs-tutorials/options-api-vs-composition-api/
5858
* and https://vuejs.org/api/composition-api-setup.html
59-
* */
60-
59+
* */
60+
6161
// We use a pinia store to store the chat messages, and status data like if there is a message stream currently happening or an error state.
6262
const chatStore = useChatStore();
6363
@@ -139,17 +139,17 @@
139139
type: 'error'
140140
});
141141
}
142-
142+
143143
} catch (error) {
144144
console.log('Error getting consent for opey from OBP: ', error)
145145
this.errorState = true
146146
ElMessage({
147147
message: 'Error getting consent for opey from OBP',
148148
type: 'error'
149149
});
150-
150+
151151
}
152-
152+
153153
},
154154
async answerConsentChallenge() {
155155
const challengeAnswer = this.consentChallengeAnswer
@@ -160,7 +160,7 @@
160160
161161
try {
162162
console.log(`Answering consent challenge with: ${challengeAnswer} and consent_id: ${this.consentId}`)
163-
163+
164164
165165
// send the challenge answer to Opey for approval
166166
const response = await axios.post(
@@ -174,7 +174,7 @@
174174
withCredentials: true,
175175
}
176176
)
177-
177+
178178
console.log("Consent challenge response: ", response.status, response.headers)
179179
if (response.status === 200) {
180180
console.log('Consent challenge answered successfully, Consent approved')
@@ -185,7 +185,7 @@
185185
} else {
186186
console.log('Consent denied')
187187
}
188-
}
188+
}
189189
} catch (error) {
190190
191191
console.log('Error answering consent challenge: ', error)
@@ -230,9 +230,9 @@
230230
},
231231
/**
232232
* This function highlights code blocks in the chat messages
233-
*
234-
* @param content
235-
* @param language
233+
*
234+
* @param content
235+
* @param language
236236
*/
237237
highlightCode(content, language) {
238238
if (Prism.languages[language]) {
@@ -365,7 +365,7 @@
365365
</button>
366366
</el-tooltip>
367367
<div class="detail">
368-
368+
369369
</div>
370370
</div>
371371
</div>
@@ -374,11 +374,11 @@
374374
<div class="dot"></div>
375375
<div class="dot"></div>
376376
</div>
377-
378-
377+
378+
379379
</div>
380380
<div v-else class="chat-messages">
381-
<p>Opey is only availabled when logged in. <a v-bind:href="'/api/connect'">Log In</a> </p>
381+
<p>Opey is only availabled when logged in. <a v-bind:href="'/api/oauth2/connect'">Log In</a> </p>
382382
</div>
383383
<el-alert
384384
v-if="this.errorState"
@@ -397,8 +397,8 @@
397397
>
398398
</el-input>
399399
<!--<textarea v-model="userInput" placeholder="Type your message..." @keypress="submitEnter"></textarea>-->
400-
<button
401-
@click="sendMessage"
400+
<button
401+
@click="sendMessage"
402402
:disabled="!isLoggedIn || this.awaitingConnection ? '' : disabled"
403403
:style="!isLoggedIn || this.awaitingConnection ? 'background-color:#929292; cursor:not-allowed' : ''"
404404
>
@@ -462,8 +462,8 @@
462462
463463
.quit-button {
464464
position: absolute;
465-
top: -12px;
466-
right: -12px;
465+
top: -12px;
466+
right: -12px;
467467
width: 24px;
468468
height: 24px;
469469
background-color: red;
@@ -654,4 +654,4 @@
654654
cursor: nwse-resize;
655655
z-index: 1001;
656656
}
657-
</style>
657+
</style>

src/components/HeaderNav.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const getCurrentPath = () => {
173173
<arrow-down />
174174
</el-icon>
175175
</span>-->
176-
<a v-bind:href="'/api/connect?redirect='+ encodeURIComponent(getCurrentPath())" v-show="isShowLoginButton" class="login-button router-link" id="login">
176+
<a v-bind:href="'/api/oauth2/connect?redirect='+ encodeURIComponent(getCurrentPath())" v-show="isShowLoginButton" class="login-button router-link" id="login">
177177
{{ $t('header.login') }}
178178
</a>
179179
<span v-show="isShowLogOffButton" class="login-user">{{ loginUsername }}</span>

0 commit comments

Comments
 (0)