MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / getDataFromAuthorizationHeader

Function getDataFromAuthorizationHeader

lib/auth.ts:100–129  ·  view source on GitHub ↗
(authorizationHeader: string)

Source from the content-addressed store, hash-verified

98}
99
100async 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
131async function getDataFromCookie(
132 cookieValue: string,

Callers 1

getDataFromRequestFunction · 0.85

Calls 3

generateHashFunction · 0.90
dataToTextFunction · 0.85
getByEmailMethod · 0.80

Tested by

no test coverage detected