Store encrypted private key in cookies

This commit is contained in:
Dominik Korsa 2021-01-19 21:39:03 +01:00
parent cc10ff441f
commit d7ee500ba6
No known key found for this signature in database
GPG key ID: 546F986F71A6FE6E
6 changed files with 20 additions and 12 deletions

View file

@ -3,9 +3,6 @@ import LoginResultStudent from './login-result-student';
@ObjectType()
export default class LoginResult {
@Field(() => String)
public encryptedPrivateKey!: string;
@Field(() => [LoginResultStudent])
public students!: LoginResultStudent[];
}

View file

@ -21,7 +21,7 @@ export default class LoginResolver {
@Arg('username') username: string,
@Arg('password') password: string,
@Arg('host') host: string,
@Ctx() { sessionData }: WebsiteAPIContext,
@Ctx() { sessionData, reply }: WebsiteAPIContext,
): Promise<LoginResult> {
const prompt = sessionData.prompts.get(promptId);
if (!prompt) throw new UnknownPromptError();
@ -55,8 +55,17 @@ export default class LoginResolver {
username,
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 {
encryptedPrivateKey,
students,
};
}

View file

@ -1,5 +1,10 @@
import type {
FastifyInstance, FastifyRequest, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerDefault,
FastifyInstance,
FastifyReply,
FastifyRequest,
RawReplyDefaultExpression,
RawRequestDefaultExpression,
RawServerDefault,
} from 'fastify';
import { registerEnumType } from 'type-graphql';
import type SessionData from './session-data';
@ -45,4 +50,5 @@ export type MyFastifyInstance = FastifyInstance<RawServerDefault, RawRequestDefa
export interface ApolloContext {
request: FastifyRequest;
reply: FastifyReply,
}

View file

@ -79,8 +79,8 @@ export default class LoginWindow extends Vue {
username: this.username,
password: this.password,
});
const { students, encryptedPrivateKey } = login;
console.log(students, encryptedPrivateKey);
const { students } = login;
console.log(students);
this.reset();
} catch (error) {
console.error(error);

View file

@ -61,7 +61,6 @@ export type MutationLoginArgs = {
export type LoginResult = {
__typename?: 'LoginResult';
encryptedPrivateKey: Scalars['String'];
students: Array<LoginResultStudent>;
};
@ -82,7 +81,6 @@ export type LoginMutation = (
{ __typename?: 'Mutation' }
& { login: (
{ __typename?: 'LoginResult' }
& Pick<LoginResult, 'encryptedPrivateKey'>
& { students: Array<(
{ __typename?: 'LoginResultStudent' }
& Pick<LoginResultStudent, 'studentId' | 'name'>
@ -114,7 +112,6 @@ export const LoginDocument = gql`
username: $username
promptId: $promptId
) {
encryptedPrivateKey
students {
studentId
name

View file

@ -2,7 +2,6 @@ import gql from 'graphql-tag';
export default gql`mutation Login($promptId: String!, $host: String!, $username: String!, $password: String!) {
login(host: $host, password: $password, username: $username, promptId: $promptId) {
encryptedPrivateKey
students {
studentId
name