(authorizationHeader: string)
| 98 | } |
| 99 | |
| 100 | async function getDataFromAuthorizationHeader(authorizationHeader: string) { |
| 101 | if (!authorizationHeader) { |
| 102 | return null; |
| 103 | } |
| 104 | |
| 105 | // Only basic auth is supported for now |
| 106 | if (!authorizationHeader.startsWith('Basic ')) { |
| 107 | return null; |
| 108 | } |
| 109 | |
| 110 | try { |
| 111 | const basicAuthHash = authorizationHeader.split('Basic ')[1] || ''; |
| 112 | |
| 113 | const [basicAuthUsername, basicAuthPassword] = dataToText(decodeBase64(basicAuthHash)).split(':'); |
| 114 | |
| 115 | const hashedPassword = await generateHash(`${basicAuthPassword}:${PASSWORD_SALT}`, 'SHA-256'); |
| 116 | |
| 117 | const user = await UserModel.getByEmail(basicAuthUsername); |
| 118 | |
| 119 | if (!user || (user.hashed_password !== hashedPassword && user.extra.dav_hashed_password !== hashedPassword)) { |
| 120 | throw new Error('Email not found or invalid password.'); |
| 121 | } |
| 122 | |
| 123 | return { user, session: undefined }; |
| 124 | } catch (error) { |
| 125 | console.error(error); |
| 126 | } |
| 127 | |
| 128 | return null; |
| 129 | } |
| 130 | |
| 131 | async function getDataFromCookie( |
| 132 | cookieValue: string, |
no test coverage detected