-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mpi auth #36
base: main
Are you sure you want to change the base?
Mpi auth #36
Conversation
Coverage report
Show new covered files 🐣
Test suite run success4 tests passing in 2 suites. Report generated by 🧪jest coverage report action from 5ab8ef2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, I added some suggestions to keep the code base cohesive
|
||
type eLabsStatus = 'PENDING' | 'PROGRESS' | 'COMPLETED'; | ||
|
||
@Controller('mpi') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this is written using REST instead of GraphQL?
import { BadRequestException, Injectable } from '@nestjs/common'; | ||
import axios from 'axios'; | ||
|
||
// type ELabsStudyResponse = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code still needed if commented out? If so, then the code should have a comment above it explaining why
|
||
// TODO: put this in an env file. | ||
private client_id = 'tZSXM9f8WUiPIpNGt1kXlGqzZVYvWNEF'; // Auth0 Damp Canvas app client ID | ||
private client_secret = 'uHw3eZ4XrYcBW1zJJqWt1dbLC6YuwCT-v0AeXa1npLuhiEkw-Ayq1wwDcw3FSgnh'; // Auth0 Damp Canvas app client secret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These shouldn't be in the code
client_id: this.client_id, | ||
client_secret: this.client_secret, | ||
code, | ||
redirect_uri: 'http://127.0.0.1:5100/mpi/auth0_redirect' // URL in this server that was used to redirect to after Auth0 login |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a configuration value
|
||
@Injectable() | ||
export class MPIService { | ||
private tokenStore = new Map<string, { accessToken: string; refreshToken: string; accessTokenExpiration: Date }>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be within MongoDB since we already have everything setup for it
const user = this.tokenStore.get(this.currentUserId); | ||
if (user && user.accessToken && user.accessTokenExpiration) { | ||
if (user.accessTokenExpiration > new Date(Date.now())) { | ||
console.log('user ', user, ' has valid token'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best to avoid having left over console.log
s
async createSequence(): Promise<any> { | ||
const token = await this.getAccessToken(); | ||
if (!token) { | ||
return new BadRequestException('No token found, log in to MPI first'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this is an Unauthroized
exception
if (!token) { | ||
return new BadRequestException('No token found, log in to MPI first'); | ||
} | ||
const sequences = await axios.get('http://localhost:5000/sequences', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL should probably be a config value
async getSequences(): Promise<any> { | ||
const token = await this.getAccessToken(); | ||
if (!token) { | ||
return new BadRequestException('No token found, log in to MPI first'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another Unauthorized
exception usage
Description
Checklist