Skip to content

Commit

Permalink
wip falcon cloud autodiscover
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Jan 13, 2022
1 parent 898faad commit 0601b92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/FalconCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ type CloudUsGov1 = "us-gov-1";

export type FalconCloud = CloudUs1 | CloudUs2 | CloudEu1 | CloudUsGov1;

export type CloudAutoDiscover = "autodiscover";
export type FalconCloudInput = FalconCloud | CloudAutoDiscover;

const CloudHost = {
"us-1": "api.crowdstrike.com",
"us-2": "api.us-2.crowdstrike.com",
Expand Down
13 changes: 11 additions & 2 deletions src/middleware/oauth2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Oauth2Api } from "../apis";
import { Configuration, FetchAPI } from "../runtime";
import { FalconCloud, CloudBasePath } from "../FalconCloud";
import { FalconCloud, FalconCloudInput, CloudBasePath } from "../FalconCloud";

type Token = {
accessToken: string;
Expand All @@ -9,7 +9,7 @@ type Token = {

type OAuth2Options = {
fetchApi?: FetchAPI;
cloud: FalconCloud;
cloud?: FalconCloudInput;
clientId: string;
clientSecret: string;
};
Expand Down Expand Up @@ -54,6 +54,15 @@ export class OAuth2 {
}

private async cloud(): Promise<FalconCloud> {
if (this.options.cloud instanceof FalconCloud) {
return this.options.cloud;
} else {
// User has not provided FalconCloud. Let's try to autodiscover.
token = OAuth2.refreshTokenInternal(FalconCloudUs1, this.options.clientId, this.options.clientSecret);
// TODO token.XCSRegion header missing
// TODO patch openapi-generator to support response headers
}

return this.options.cloud;
}

Expand Down

0 comments on commit 0601b92

Please sign in to comment.