Skip to content

Commit

Permalink
perf(sme): add separate env for SME OAuth (#11776)
Browse files Browse the repository at this point in the history
* perf(sme): add separate env for SME OAuth

* perf: remove unused code

---------

Co-authored-by: rentu <rentu@microsoft.com>
  • Loading branch information
SLdragon and SLdragon authored Jun 6, 2024
1 parent af81590 commit 0045067
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/fx-core/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class FeatureFlagName {
static readonly ChatParticipant = "TEAMSFX_CHAT_PARTICIPANT";
static readonly NewGenerator = "TEAMSFX_NEW_GENERATOR";
static readonly CopilotAuth = "API_COPILOT_PLUGIN_AUTH";
static readonly SMEOAuth = "SME_OAUTH";
static readonly CustomizeGpt = "TEAMSFX_DECLARATIVE_COPILOT";
}

Expand Down
5 changes: 5 additions & 0 deletions packages/fx-core/src/common/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export function isCopilotAuthEnabled(): boolean {
return featureFlagManager.getBooleanValue(FeatureFlags.CopilotAuth);
}

export function isSMEOAuthEnabled(): boolean {
return featureFlagManager.getBooleanValue(FeatureFlags.SMEOAuth);
}

///////////////////////////////////////////////////////////////////////////////
// Notes for Office Addin Feature flags:
// Case 1: TEAMSFX_OFFICE_ADDIN = false, TEAMSFX_OFFICE_XML_ADDIN = false
Expand Down Expand Up @@ -147,6 +151,7 @@ export class FeatureFlags {
defaultValue: "false",
};
static readonly CopilotAuth = { name: FeatureFlagName.CopilotAuth, defaultValue: "false" };
static readonly SMEOAuth = { name: FeatureFlagName.SMEOAuth, defaultValue: "false" };
static readonly CustomizeGpt = { name: FeatureFlagName.CustomizeGpt, defaultValue: "false" };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import * as fs from "fs-extra";
import { merge } from "lodash";
import path from "path";
import * as util from "util";
import { isCopilotAuthEnabled } from "../../../common/featureFlags";
import { isSMEOAuthEnabled } from "../../../common/featureFlags";
import { getLocalizedString } from "../../../common/localizeUtils";
import { isValidHttpUrl } from "../../../common/stringUtils";
import { assembleError } from "../../../error";
Expand Down Expand Up @@ -429,7 +429,7 @@ export class CopilotGenerator extends DefaultTemplateGenerator {
allowBearerTokenAuth: true, // Currently, API key auth support is actually bearer token auth
allowMultipleParameters: true,
projectType: getTemplateInfosState.type,
allowOauth2: isCopilotAuthEnabled(),
allowOauth2: isSMEOAuthEnabled(),
}
);
const validationRes = await specParser.validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import fs from "fs-extra";
import { OpenAPIV3 } from "openapi-types";
import { EOL } from "os";
import path from "path";
import { isCopilotAuthEnabled } from "../../../common/featureFlags";
import { isCopilotAuthEnabled, isSMEOAuthEnabled } from "../../../common/featureFlags";
import { getLocalizedString } from "../../../common/localizeUtils";
import { sendRequestWithRetry } from "../../../common/requestUtils";
import { MissingRequiredInputError } from "../../../error";
Expand Down Expand Up @@ -136,7 +136,7 @@ export async function listOperations(
: {
allowBearerTokenAuth: true, // Currently, API key auth support is actually bearer token auth
allowMultipleParameters: true,
allowOauth2: isCopilotAuthEnabled(),
allowOauth2: isSMEOAuthEnabled(),
}
);
const validationRes = await specParser.validate();
Expand Down
9 changes: 1 addition & 8 deletions packages/spec-parser/src/manifestUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,27 +341,20 @@ export class ManifestUpdater {
`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`
);
if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`
);
(composeExtension as any).authorization = {
authType: "apiSecretServiceAuth",
apiSecretServiceAuthConfiguration: {
apiSecretRegistrationId: `\${{${safeRegistrationIdName}}}`,
},
};
} else if (Utils.isOAuthWithAuthCodeFlow(auth)) {
// TODO: below schema is coming from design doc, may need to update when shcema is finalized
(composeExtension as any).authorization = {
authType: "oAuth2.0",
oAuthConfiguration: {
oauthConfigurationId: `\${{${safeRegistrationIdName}}}`,
},
};

updatedPart.webApplicationInfo = {
id: "${{AAD_APP_CLIENT_ID}}",
resource: "api://${{DOMAIN}}/${{AAD_APP_CLIENT_ID}}",
};
}
}

Expand Down
4 changes: 0 additions & 4 deletions packages/spec-parser/test/manifestUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3785,10 +3785,6 @@ describe("manifestUpdater", () => {
],
},
],
webApplicationInfo: {
id: "${{AAD_APP_CLIENT_ID}}",
resource: "api://${{DOMAIN}}/${{AAD_APP_CLIENT_ID}}",
},
};
const readJSONStub = sinon.stub(fs, "readJSON").resolves(originalManifest);
const oauth2: AuthInfo = {
Expand Down

0 comments on commit 0045067

Please sign in to comment.