Figure out user manager for account user
This commit is contained in:
parent
3492558e06
commit
95a8e64fbb
16 changed files with 152 additions and 106 deletions
|
@ -99,17 +99,17 @@ export const unmatchedTags = (tags) => {
|
|||
else return tags.filter(tag => !(tag in emojis));
|
||||
}
|
||||
|
||||
export const maybeWithBasicAuth = (headers, user) => {
|
||||
if (user) {
|
||||
headers['Authorization'] = `Basic ${encodeBase64(`${user.username}:${user.password}`)}`;
|
||||
export const maybeWithAuth = (headers, user) => {
|
||||
if (user && user.password) {
|
||||
return withBasicAuth(headers, user.username, user.password);
|
||||
} else if (user && user.token) {
|
||||
return withBearerAuth(headers, user.token);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
export const maybeWithBearerAuth = (headers, token) => {
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
export const withBasicAuth = (headers, username, password) => {
|
||||
headers['Authorization'] = basicAuth(username, password);
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,15 @@ export const basicAuth = (username, password) => {
|
|||
return `Basic ${encodeBase64(`${username}:${password}`)}`;
|
||||
}
|
||||
|
||||
export const withBearerAuth = (headers, token) => {
|
||||
headers['Authorization'] = bearerAuth(token);
|
||||
return headers;
|
||||
}
|
||||
|
||||
export const bearerAuth = (token) => {
|
||||
return `Bearer ${token}`;
|
||||
}
|
||||
|
||||
export const encodeBase64 = (s) => {
|
||||
return Base64.encode(s);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue