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

perf(sme): add separate env for SME OAuth #11776

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to use unified global feature flag manager directly: featureFlagManager.getBooleanValue(FeatureFlags.SMEOAuth)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we plan to update it in another PR

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 { merge } from "lodash";
import path from "path";
import * as util from "util";
import { isCopilotAuthEnabled } from "../../../common/featureFlags";
import { isCopilotAuthEnabled, isSMEOAuthEnabled } from "../../../common/featureFlags";
Fixed Show fixed Hide fixed
import { getLocalizedString } from "../../../common/localizeUtils";
import { isValidHttpUrl } from "../../../common/stringUtils";
import { assembleError } from "../../../error";
Expand Down Expand Up @@ -429,7 +429,7 @@
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
Loading