Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAuthHeader not compatible with token provided by admin dashboard. #12

Open
brendanmoore opened this issue Feb 19, 2024 · 0 comments
Open

Comments

@brendanmoore
Copy link

It appears the admin dashboard will give you an API token that is an "already base64 encoded" representation of a email/pass so the getAuthHeader doesn't really support it. I.e. bearer rejects it as unauthorised and basic will double encode it.

export function getAuthHeader(auth: Auth) {
if (auth.type === 'bearer') {
return `Bearer ${auth.token}`;
} else if (auth.type === 'basic') {
return `Basic ${btoa(`${auth.username}:${auth.password}`)}`;
} else if (auth.type === 'key') {
return `Client-Key ${auth.clientKey}`;
} else {
throw new Error(`Unknown auth type: ${auth}`);
}
}

A potential solution could be that a pre-encoded basic token could be passed instead of user/pass for type basic e.g.:

export function getAuthHeader(auth: Auth) { 
     if (auth.type === 'bearer') { 
         return `Bearer ${auth.token}`; 
     } else if (auth.type === 'basic') { 
         return `Basic ${auth.token ? auth.token : btoa(`${auth.username}:${auth.password}`)}`; 
     } else if (auth.type === 'key') { 
         return `Client-Key ${auth.clientKey}`; 
     } else { 
         throw new Error(`Unknown auth type: ${auth}`); 
     } 
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant