Store encrypted private key in cookies
This commit is contained in:
parent
cc10ff441f
commit
d7ee500ba6
6 changed files with 20 additions and 12 deletions
|
@ -3,9 +3,6 @@ import LoginResultStudent from './login-result-student';
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export default class LoginResult {
|
export default class LoginResult {
|
||||||
@Field(() => String)
|
|
||||||
public encryptedPrivateKey!: string;
|
|
||||||
|
|
||||||
@Field(() => [LoginResultStudent])
|
@Field(() => [LoginResultStudent])
|
||||||
public students!: LoginResultStudent[];
|
public students!: LoginResultStudent[];
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ export default class LoginResolver {
|
||||||
@Arg('username') username: string,
|
@Arg('username') username: string,
|
||||||
@Arg('password') password: string,
|
@Arg('password') password: string,
|
||||||
@Arg('host') host: string,
|
@Arg('host') host: string,
|
||||||
@Ctx() { sessionData }: WebsiteAPIContext,
|
@Ctx() { sessionData, reply }: WebsiteAPIContext,
|
||||||
): Promise<LoginResult> {
|
): Promise<LoginResult> {
|
||||||
const prompt = sessionData.prompts.get(promptId);
|
const prompt = sessionData.prompts.get(promptId);
|
||||||
if (!prompt) throw new UnknownPromptError();
|
if (!prompt) throw new UnknownPromptError();
|
||||||
|
@ -55,8 +55,17 @@ export default class LoginResolver {
|
||||||
username,
|
username,
|
||||||
availableStudentIds: students.map(({ studentId }) => studentId),
|
availableStudentIds: students.map(({ studentId }) => studentId),
|
||||||
};
|
};
|
||||||
|
// TODO: Find why the promise never resolves
|
||||||
|
reply.setCookie('epk', encryptedPrivateKey, {
|
||||||
|
sameSite: 'strict',
|
||||||
|
httpOnly: true,
|
||||||
|
path: '/',
|
||||||
|
maxAge: 3600,
|
||||||
|
});
|
||||||
|
// In case execution of setCookie takes some time
|
||||||
|
// TODO: Remove
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||||
return {
|
return {
|
||||||
encryptedPrivateKey,
|
|
||||||
students,
|
students,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
import type {
|
import type {
|
||||||
FastifyInstance, FastifyRequest, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerDefault,
|
FastifyInstance,
|
||||||
|
FastifyReply,
|
||||||
|
FastifyRequest,
|
||||||
|
RawReplyDefaultExpression,
|
||||||
|
RawRequestDefaultExpression,
|
||||||
|
RawServerDefault,
|
||||||
} from 'fastify';
|
} from 'fastify';
|
||||||
import { registerEnumType } from 'type-graphql';
|
import { registerEnumType } from 'type-graphql';
|
||||||
import type SessionData from './session-data';
|
import type SessionData from './session-data';
|
||||||
|
@ -45,4 +50,5 @@ export type MyFastifyInstance = FastifyInstance<RawServerDefault, RawRequestDefa
|
||||||
|
|
||||||
export interface ApolloContext {
|
export interface ApolloContext {
|
||||||
request: FastifyRequest;
|
request: FastifyRequest;
|
||||||
|
reply: FastifyReply,
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,8 @@ export default class LoginWindow extends Vue {
|
||||||
username: this.username,
|
username: this.username,
|
||||||
password: this.password,
|
password: this.password,
|
||||||
});
|
});
|
||||||
const { students, encryptedPrivateKey } = login;
|
const { students } = login;
|
||||||
console.log(students, encryptedPrivateKey);
|
console.log(students);
|
||||||
this.reset();
|
this.reset();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
|
@ -61,7 +61,6 @@ export type MutationLoginArgs = {
|
||||||
|
|
||||||
export type LoginResult = {
|
export type LoginResult = {
|
||||||
__typename?: 'LoginResult';
|
__typename?: 'LoginResult';
|
||||||
encryptedPrivateKey: Scalars['String'];
|
|
||||||
students: Array<LoginResultStudent>;
|
students: Array<LoginResultStudent>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -82,7 +81,6 @@ export type LoginMutation = (
|
||||||
{ __typename?: 'Mutation' }
|
{ __typename?: 'Mutation' }
|
||||||
& { login: (
|
& { login: (
|
||||||
{ __typename?: 'LoginResult' }
|
{ __typename?: 'LoginResult' }
|
||||||
& Pick<LoginResult, 'encryptedPrivateKey'>
|
|
||||||
& { students: Array<(
|
& { students: Array<(
|
||||||
{ __typename?: 'LoginResultStudent' }
|
{ __typename?: 'LoginResultStudent' }
|
||||||
& Pick<LoginResultStudent, 'studentId' | 'name'>
|
& Pick<LoginResultStudent, 'studentId' | 'name'>
|
||||||
|
@ -114,7 +112,6 @@ export const LoginDocument = gql`
|
||||||
username: $username
|
username: $username
|
||||||
promptId: $promptId
|
promptId: $promptId
|
||||||
) {
|
) {
|
||||||
encryptedPrivateKey
|
|
||||||
students {
|
students {
|
||||||
studentId
|
studentId
|
||||||
name
|
name
|
||||||
|
|
|
@ -2,7 +2,6 @@ import gql from 'graphql-tag';
|
||||||
|
|
||||||
export default gql`mutation Login($promptId: String!, $host: String!, $username: String!, $password: String!) {
|
export default gql`mutation Login($promptId: String!, $host: String!, $username: String!, $password: String!) {
|
||||||
login(host: $host, password: $password, username: $username, promptId: $promptId) {
|
login(host: $host, password: $password, username: $username, promptId: $promptId) {
|
||||||
encryptedPrivateKey
|
|
||||||
students {
|
students {
|
||||||
studentId
|
studentId
|
||||||
name
|
name
|
||||||
|
|
Loading…
Reference in a new issue