Skip to content

Commit

Permalink
fix(csharp): token provider correctly references underlying endpoint (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Oct 8, 2024
1 parent 37b2769 commit 10de220
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
27 changes: 15 additions & 12 deletions generators/csharp/sdk/src/oauth/OauthTokenProviderGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class OauthTokenProviderGenerator extends FileGenerator<CSharpFile, SdkCu
private tokenEndpointHttpService: HttpService;
private tokenEndpointReference: EndpointReference;
private tokenEndpoint: HttpEndpoint;
private clientField: csharp.Field;

private static readonly BUFFER_IN_MINUTES_FIELD = csharp.field({
access: "private",
Expand Down Expand Up @@ -72,6 +73,13 @@ export class OauthTokenProviderGenerator extends FileGenerator<CSharpFile, SdkCu
this.tokenEndpointReference.endpointId
);
this.tokenEndpoint = httpEndpoint;
this.clientField = csharp.field({
access: "private",
name: "_client",
type: csharp.Type.reference(
this.context.getSubpackageClassReferenceForServiceIdOrThrow(this.tokenEndpointReference.serviceId)
)
});
}

public doGenerate(): CSharpFile {
Expand All @@ -91,14 +99,7 @@ export class OauthTokenProviderGenerator extends FileGenerator<CSharpFile, SdkCu
class_.addField(OauthTokenProviderGenerator.CLIENT_ID_FIELD);
class_.addField(OauthTokenProviderGenerator.CLIENT_SECRET_FIELD);

const clientField = csharp.field({
access: "private",
name: "_client",
type: csharp.Type.reference(
this.context.getSubpackageClassReferenceForServiceIdOrThrow(this.tokenEndpointReference.serviceId)
)
});
class_.addField(clientField);
class_.addField(this.clientField);

class_.addMethod(this.getAccessTokenMethod());

Expand All @@ -115,13 +116,13 @@ export class OauthTokenProviderGenerator extends FileGenerator<CSharpFile, SdkCu
}),
csharp.parameter({
name: "client",
type: clientField.type
type: this.clientField.type
})
],
body: csharp.codeblock((writer) => {
writer.writeTextStatement(`${OauthTokenProviderGenerator.CLIENT_ID_FIELD.name} = clientId`);
writer.writeTextStatement(`${OauthTokenProviderGenerator.CLIENT_SECRET_FIELD.name} = clientSecret`);
writer.writeTextStatement(`${clientField.name} = client`);
writer.writeTextStatement(`${this.clientField.name} = client`);
})
});

Expand Down Expand Up @@ -194,7 +195,9 @@ export class OauthTokenProviderGenerator extends FileGenerator<CSharpFile, SdkCu
writer.writeNode(
csharp.invokeMethod({
async: true,
method: `client.${this.tokenEndpoint.name.pascalCase.safeName}`,
method: `${this.clientField.name}.${this.context.getEndpointMethodName(
this.tokenEndpoint
)}`,
arguments_: [
csharp.instantiateClass({
classReference: requestType.internalType.value,
Expand Down Expand Up @@ -246,7 +249,7 @@ export class OauthTokenProviderGenerator extends FileGenerator<CSharpFile, SdkCu

writer.endControlFlow();

writer.writeTextStatement(`return $"Bearer \{${OauthTokenProviderGenerator.ACCESS_TOKEN_FIELD.name}\}"`);
writer.writeTextStatement(`return $"Bearer {${OauthTokenProviderGenerator.ACCESS_TOKEN_FIELD.name}}"`);
});
}

Expand Down
8 changes: 8 additions & 0 deletions generators/csharp/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
- version: 1.8.1
irVersion: 53
createdAt: '2024-10-08'
changelogEntry:
- type: fix
summary: |
Fixes a bug where the `OauthTokenProvider.cs` was incorrectly referencing
the endpoint method, causing code to fail to compile.
- version: 1.8.0
createdAt: '2024-08-29'
changelogEntry:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 10de220

Please sign in to comment.