Skip to content

Commit dbb3085

Browse files
authored
Fix: oauth implicit flow should generate none authentication (#6479)
1 parent 405bc6c commit dbb3085

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/Kiota.Builder/Plugins/PluginsGenerationService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ private static Auth GetAuthFromSecuritySchemeReference(OpenApiSecuritySchemeRefe
611611
{
612612
ReferenceId = string.IsNullOrEmpty(authenticationReferenceId) ? $"{{{name}_REGISTRATION_ID}}" : authenticationReferenceId
613613
},
614+
SecuritySchemeType.OAuth2 when securityScheme.Flows?.Implicit != null => new AnonymousAuth(),
614615
SecuritySchemeType.OAuth2 => new OAuthPluginVault
615616
{
616617
ReferenceId = string.IsNullOrEmpty(authenticationReferenceId) ? $"{{{name}_REGISTRATION_ID}}" : authenticationReferenceId

tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,18 @@ public static TheoryData<string, string, string, PluginAuthConfiguration, Action
551551
Assert.Equal("{oauth2_0_REGISTRATION_ID}", ((OAuthPluginVault)auth0!).ReferenceId);
552552
}
553553
},
554+
// OAuth2 with implicit flow should return (None)
555+
{
556+
"{securitySchemes: {oauth2_implicit: {type: oauth2, flows: {implicit: {authorizationUrl: 'https://example.com/auth'}}}}}",
557+
string.Empty, "security: [oauth2_implicit: []]", null, resultingManifest =>
558+
{
559+
Assert.NotNull(resultingManifest.Document);
560+
Assert.Empty(resultingManifest.Problems);
561+
Assert.NotEmpty(resultingManifest.Document.Runtimes);
562+
var auth = resultingManifest.Document.Runtimes[0].Auth;
563+
Assert.IsType<AnonymousAuth>(auth);
564+
}
565+
},
554566
// should be anonymous
555567
{
556568
"{}", string.Empty, "security: [invalid: []]", null, resultingManifest =>

vscode/npm-package/tests/integration/integrationGeneratePlugin.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ describe("GeneratePlugin", () => {
6565
descriptionPath: actual?.aiPlugin
6666
});
6767
expect(actualPluginManifest).toBeDefined();
68-
expect(actualPluginManifest?.runtime[0].auth.type).toEqual('OAuthPluginVault');
69-
expect(actualPluginManifest?.runtime[0].auth.reference_id).toEqual('{oAuth2AuthCode_REGISTRATION_ID}');
68+
expect(actualPluginManifest?.runtime[0].auth.type).toEqual('None');
7069
expect(actualPluginManifest?.runtime[0].run_for_functions[0]).toEqual('listRepairs');
7170
expect(actualPluginManifest?.runtime[0].run_for_functions[1]).toEqual('repairs_post');
7271
expect(actualPluginManifest?.functions[0].name).toEqual('listRepairs');
@@ -86,7 +85,7 @@ describe("GeneratePlugin", () => {
8685
}
8786
const actualSecurityScheme = actualSecuritySchemes['oAuth2AuthCode'];
8887
expect(actualSecurityScheme).toBeDefined();
89-
expect(actualSecurityScheme.referenceId).toEqual('{oAuth2AuthCode_REGISTRATION_ID}');
88+
expect(actualSecurityScheme.referenceId).toEqual('');
9089
});
9190

9291

0 commit comments

Comments
 (0)