Skip to content

Commit

Permalink
check if auth data exists before using
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Jul 8, 2024
1 parent ddd1634 commit 493b56f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AuthorizationResult } from '../types/state/authorization.interface';

export interface AuthorizationProviderExecuteOptions<T = unknown> {
// The input from the user
data: T;
data: T | undefined;
}

export abstract class AuthorizationProvider<T = unknown> {
Expand Down
2 changes: 1 addition & 1 deletion packages/altair-core/src/authorization/providers/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class BasicAuthorizationProvider extends AuthorizationProvider<Ba
async execute(
options: AuthorizationProviderExecuteOptions<BasicAuthorizationProviderData>
): Promise<AuthorizationResult> {
if (!options.data.username || !options.data.password) {
if (!options.data?.username || !options.data?.password) {
return {
headers: {},
};
Expand Down
5 changes: 5 additions & 0 deletions packages/altair-core/src/authorization/providers/bearer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default class BearerAuthorizationProvider extends AuthorizationProvider<B
async execute(
options: AuthorizationProviderExecuteOptions<BearerAuthorizationProviderData>
): Promise<AuthorizationResult> {
if (!options.data?.token) {
return {
headers: {},
};
}
return {
headers: {
Authorization: `Bearer ${this.hydrate(options.data.token)}`,
Expand Down
5 changes: 5 additions & 0 deletions packages/altair-core/src/authorization/providers/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export default class OAuth2AuthorizationProvider extends AuthorizationProvider<O
async execute(
options: AuthorizationProviderExecuteOptions<OAuth2AuthorizationProviderData>
): Promise<AuthorizationResult> {
if (!options.data?.accessTokenResponse) {
return {
headers: {},
};
}
return {
headers: {
Authorization: `Bearer ${this.hydrate(options.data.accessTokenResponse.access_token)}`,
Expand Down

0 comments on commit 493b56f

Please sign in to comment.