Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Mpi auth #36

wants to merge 4 commits into from

Conversation

chris-krenz
Copy link

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Checklist

  • This PR can be reviewed in under 30 minutes
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have assigned reviewers to this PR.

Copy link

Coverage report

St.
Category Percentage Covered / Total
🔴 Statements
2.78% (-0.38% 🔻)
27/971
🔴 Branches 0% 0/50
🔴 Functions
2.6% (-0.24% 🔻)
7/269
🔴 Lines
2.27% (-0.38% 🔻)
18/794
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / mpi.controller.ts
0% 100% 0% 0%
🔴 mpi/mpi.service.ts 0% 0% 0% 0%

Test suite run success

4 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from 5ab8ef2

Copy link
Member

@cbolles cbolles left a 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')
Copy link
Member

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 = {
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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 }>();
Copy link
Member

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');
Copy link
Member

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.logs

async createSequence(): Promise<any> {
const token = await this.getAccessToken();
if (!token) {
return new BadRequestException('No token found, log in to MPI first');
Copy link
Member

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', {
Copy link
Member

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another Unauthorized exception usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants