From b32bd95896717673d0cf39c26d266d1cde1d4b8d Mon Sep 17 00:00:00 2001 From: verybadsoldier Date: Mon, 24 Apr 2023 20:57:51 +0200 Subject: [PATCH] header_sso: adaptions for changed internals --- backend/internal/core/services/service_user.go | 12 ------------ frontend/composables/use-auth-context.ts | 12 ++++++++++++ frontend/pages/index.vue | 9 +-------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/backend/internal/core/services/service_user.go b/backend/internal/core/services/service_user.go index cb344e1..7df2b01 100644 --- a/backend/internal/core/services/service_user.go +++ b/backend/internal/core/services/service_user.go @@ -204,18 +204,6 @@ func (svc *UserService) LoginWithoutPassword(ctx context.Context, username strin return svc.createSessionToken(ctx, usr.ID, extendedSession) } -func (svc *UserService) LoginWithoutPassword(ctx context.Context, username string) (UserAuthTokenDetail, error) { - usr, err := svc.repos.Users.GetOneEmail(ctx, username) - - if err != nil { - // SECURITY: Perform hash to ensure response times are the same - hasher.CheckPasswordHash("not-a-real-password", "not-a-real-password") - return UserAuthTokenDetail{}, ErrorInvalidLogin - } - - return svc.createSessionToken(ctx, usr.ID) -} - func (svc *UserService) Logout(ctx context.Context, token string) error { hash := hasher.HashToken(token) err := svc.repos.AuthTokens.DeleteToken(ctx, hash) diff --git a/frontend/composables/use-auth-context.ts b/frontend/composables/use-auth-context.ts index bcffad7..cd10ffc 100644 --- a/frontend/composables/use-auth-context.ts +++ b/frontend/composables/use-auth-context.ts @@ -122,6 +122,18 @@ class AuthContext implements IAuthContext { return r; } + async login_sso_header(api: PublicApi) { + const r = await api.login_sso_header(); + + if (!r.error) { + this._token.value = r.data.token; + this._expiresAt.value = r.data.expiresAt as string; + this._attachmentToken.value = r.data.attachmentToken; + } + + return r; + } + async logout(api: UserClient) { const r = await api.user.logout(); diff --git a/frontend/pages/index.vue b/frontend/pages/index.vue index edecfd9..2bb0d94 100644 --- a/frontend/pages/index.vue +++ b/frontend/pages/index.vue @@ -32,16 +32,9 @@ } }); - const { data, error } = await api.login_sso_header(); + const { error } = await ctx.login_sso_header(api); if (!error) { - // @ts-expect-error - expires is either a date or a string, need to figure out store typing - authStore.$patch({ - token: data.token, - expires: data.expiresAt, - attachmentToken: data.attachmentToken, - }); - navigateTo("/home"); }