Repository: microsoft/kiota (csharp)

Issue:
Align auth reference id to use _REGISTRATION_ID suffix
### Overview

Alignment of reference_id for integration with TTK to add _REGISTRATION_ID suffix for all authentication types when not explicitly indicated.
Currently, when there is no an explicit reference_id, for integration with earlier TTK integration, the suffix was dependant on the authentication type. OAuth2 was adding _CONFIGURATION_ID and the rest was using _REGISTRATION_ID.

### Acceptance Criteria

The suffix for OAuth2 should use _REFERENCE_ID suffix like other authentication methods

Pull request description:
It closes #6441

Patch:
diff --git a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs
index cc481b6376..f1f683a1c5 100644
--- a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs
+++ b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs
@@ -613,7 +613,7 @@ private static Auth GetAuthFromSecuritySchemeReference(OpenApiSecuritySchemeRefe
             },
             SecuritySchemeType.OAuth2 => new OAuthPluginVault
             {
-                ReferenceId = string.IsNullOrEmpty(authenticationReferenceId) ? $"{{{name}_CONFIGURATION_ID}}" : authenticationReferenceId
+                ReferenceId = string.IsNullOrEmpty(authenticationReferenceId) ? $"{{{name}_REGISTRATION_ID}}" : authenticationReferenceId
             },
             _ => null
         };


Test patch:
diff --git a/tests/Kiota.Builder.IntegrationTests/PluginModelWithSecurity.json b/tests/Kiota.Builder.IntegrationTests/PluginModelWithSecurity.json
index e45f5d583f..cbae3ab355 100644
--- a/tests/Kiota.Builder.IntegrationTests/PluginModelWithSecurity.json
+++ b/tests/Kiota.Builder.IntegrationTests/PluginModelWithSecurity.json
@@ -24,7 +24,7 @@
       "type": "OpenApi",
       "auth": {
         "type": "OAuthPluginVault",
-        "reference_id": "{oAuth2AuthCode_CONFIGURATION_ID}"
+        "reference_id": "{oAuth2AuthCode_REGISTRATION_ID}"
       },
       "spec": {
         "url": "withsecurity-openapi.yml"
@@ -34,4 +34,4 @@
       ]
     }
   ]
-}
\ No newline at end of file
+}
diff --git a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs
index 629680b053..eaa9bebf3d 100644
--- a/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs
+++ b/tests/Kiota.Builder.Tests/Plugins/PluginsGenerationServiceTests.cs
@@ -537,6 +537,20 @@ public static TheoryData<string, string, string, PluginAuthConfiguration, Action
                     Assert.Equal("auth1234", ((OAuthPluginVault)auth0!).ReferenceId);
                 }
             },
+            // oauth2 without reference id
+            {
+                "{securitySchemes: {oauth2_0: {type: oauth2, flows: {}}}}",
+                string.Empty, "security: [oauth2_0: []]", null, resultingManifest =>
+                {
+                    Assert.NotNull(resultingManifest.Document);
+                    Assert.Empty(resultingManifest.Problems);
+                    Assert.NotEmpty(resultingManifest.Document.Runtimes);
+                    var auth0 = resultingManifest.Document.Runtimes[0].Auth;
+                    Assert.IsType<OAuthPluginVault>(auth0);
+                    Assert.Equal(AuthType.OAuthPluginVault, auth0?.Type);
+                    Assert.Equal("{oauth2_0_REGISTRATION_ID}", ((OAuthPluginVault)auth0!).ReferenceId);
+                }
+            },
             // should be anonymous
             {
                 "{}", string.Empty, "security: [invalid: []]", null, resultingManifest =>
diff --git a/vscode/npm-package/tests/integration/integrationGeneratePlugin.spec.ts b/vscode/npm-package/tests/integration/integrationGeneratePlugin.spec.ts
index 4d93ba125a..b01253e6a2 100644
--- a/vscode/npm-package/tests/integration/integrationGeneratePlugin.spec.ts
+++ b/vscode/npm-package/tests/integration/integrationGeneratePlugin.spec.ts
@@ -3,6 +3,7 @@ import { generatePlugin } from '../../lib/generatePlugin';
 import { getKiotaTree } from '../../lib/getKiotaTree';
 import { getPluginManifest } from '../../lib/getPluginManifest';
 import { KiotaPluginType, ConsumerOperation } from '../../types';
+import { PluginAuthType } from '../../types';
 
 describe("GeneratePlugin", () => {
   test('generatePlugin_Simple', async () => {
@@ -65,7 +66,7 @@ describe("GeneratePlugin", () => {
     });
     expect(actualPluginManifest).toBeDefined();
     expect(actualPluginManifest?.runtime[0].auth.type).toEqual('OAuthPluginVault');
-    expect(actualPluginManifest?.runtime[0].auth.reference_id).toEqual('{oAuth2AuthCode_CONFIGURATION_ID}');
+    expect(actualPluginManifest?.runtime[0].auth.reference_id).toEqual('{oAuth2AuthCode_REGISTRATION_ID}');
     expect(actualPluginManifest?.runtime[0].run_for_functions[0]).toEqual('listRepairs');
     expect(actualPluginManifest?.runtime[0].run_for_functions[1]).toEqual('repairs_post');
     expect(actualPluginManifest?.functions[0].name).toEqual('listRepairs');
@@ -85,7 +86,7 @@ describe("GeneratePlugin", () => {
     }
     const actualSecurityScheme = actualSecuritySchemes['oAuth2AuthCode'];
     expect(actualSecurityScheme).toBeDefined();
-    expect(actualSecurityScheme.referenceId).toEqual('{oAuth2AuthCode_CONFIGURATION_ID}');
+    expect(actualSecurityScheme.referenceId).toEqual('{oAuth2AuthCode_REGISTRATION_ID}');
   });
 
   
@@ -140,4 +141,59 @@ describe("GeneratePlugin", () => {
     expect(actualSecurityScheme).toBeDefined();
     expect(actualSecurityScheme.referenceId).toEqual('otherValue123');
   });
+
+  test('generatePlugin_withExplicitAuthTypeAndRefId', async () => {
+    const descriptionUrl = '../../tests/Kiota.Builder.IntegrationTests/ModelWithRefIdExtension.yaml';
+    const outputPath = './.tests_output';
+    const pluginName = 'withrefidandsecurity2';
+
+    const pluginType = KiotaPluginType.ApiPlugin;
+    const actual = await generatePlugin({
+      descriptionPath: descriptionUrl,
+      outputPath: outputPath,
+      clearCache: false,
+      pluginType: pluginType,
+      pluginName: pluginName,
+      operation: ConsumerOperation.Generate,
+      workingDirectory: '',
+      pluginAuthType: PluginAuthType.apiKeyPluginVault,
+      pluginAuthRefid: 'explicitRefId'
+    });
+    expect(actual).toBeDefined();
+
+    expect(actual).toBeDefined();
+    expect(actual?.aiPlugin).toEqual(path.join(outputPath, `${pluginName.toLowerCase()}-apiplugin.json`));
+    expect(actual?.openAPISpec).toEqual(path.join(outputPath, `${pluginName.toLowerCase()}-openapi.yml`));
+
+    if (!actual?.aiPlugin) {
+      throw new Error('aiPlugin should be defined');
+    }
+    const actualPluginManifest = await getPluginManifest({
+      descriptionPath: actual?.aiPlugin
+    });
+    expect(actualPluginManifest).toBeDefined();
+    expect(actualPluginManifest?.runtime[0].auth.type).toEqual('ApiKeyPluginVault');
+    expect(actualPluginManifest?.runtime[0].auth.reference_id).toEqual('explicitRefId');
+    expect(actualPluginManifest?.runtime[0].run_for_functions[0]).toEqual('listRepairs');
+    expect(actualPluginManifest?.runtime[0].run_for_functions[1]).toEqual('repairs_post');
+    expect(actualPluginManifest?.functions[0].name).toEqual('listRepairs');
+    expect(actualPluginManifest?.functions[1].name).toEqual('repairs_post');
+
+    if (!actual?.openAPISpec) {
+      throw new Error('descriptionPath should be defined');
+    }
+    const actualApiManifest = await getKiotaTree({
+      descriptionPath: actual?.openAPISpec,
+    });
+    expect(actualApiManifest).toBeDefined();
+    const actualSecuritySchemes = actualApiManifest?.securitySchemes;
+    expect(actualSecuritySchemes).toBeDefined();
+    if (!actualSecuritySchemes) {
+      throw new Error('securitySchemes should be defined');
+    }
+    const actualSecurityScheme = actualSecuritySchemes['oAuth2AuthCode'];
+    expect(actualSecurityScheme).toBeDefined();
+    expect(actualSecurityScheme.referenceId).toEqual('otherValue123');
+  });
+
 });
\ No newline at end of file