Skip to content

[FEATURE] Implement AuthMethod.Login#616

Merged
marcin-krystianc merged 11 commits intoG-Research:masterfrom
MohamedM216:authmethod-login
Apr 2, 2026
Merged

[FEATURE] Implement AuthMethod.Login#616
marcin-krystianc merged 11 commits intoG-Research:masterfrom
MohamedM216:authmethod-login

Conversation

@MohamedM216
Copy link
Copy Markdown
Contributor

@MohamedM216 MohamedM216 commented Mar 30, 2026

Description

Implement AuthMethod.Login. See https://developer.hashicorp.com/consul/api-docs/acl#login-to-auth-method

Related Issues

#615

Additional Context

Checklist

Please make sure to check the following before submitting your pull request:

  • Did you read the contributing guidelines?
  • Did you update the docs?
  • Did you write any tests to validate this change?

Comment thread Consul.Test/AuthMethodTest.cs Outdated
var authMethod = await _client.AuthMethod.Create(authMethodEntry);
Assert.NotNull(authMethod.Response);

var res = await _client.AuthMethod.Login(authMethod.Response.Name, null /* the application's bearer token */, WriteOptions.Default);
Copy link
Copy Markdown
Contributor Author

@MohamedM216 MohamedM216 Mar 30, 2026

Choose a reason for hiding this comment

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

the application's bearer token: BearerToken, I think this is what's only missing now. @marcin-krystianc , I'd appreciate your help in how to get it. It's different from ServiceAccountJWT, I tried the latter, but the test failed with FAILED: AuthMethod_Login (30060ms) Consul.ConsulRequestException : Unexpected response, status code InternalServerError: Post "https://192.0.2.42:8443/apis/authentication.k8s.io/v1/tokenreviews": dial tcp 192.0.2.42:8443: i/o timeout

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ExportRSAPublicKeyPem() and CreateSignedJwt() aren't declared in the codebase: The name 'ExportRSAPublicKeyPem' does not exist in the current context[CS0103]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ExportRSAPublicKeyPem() and CreateSignedJwt() aren't declared in the codebase: The name 'ExportRSAPublicKeyPem' does not exist in the current context[CS0103]

Implementation of these methods is available in the linked commit.

Comment thread Consul/AuthMethod.cs
AuthMethod = AuthMethod,
BearerToken = BearerToken
};
var res = await _client.Post<LoginRequest, TokenEntry>("/v1/acl/login", loginRequest, writeOptions).Execute(ct).ConfigureAwait(false);
Copy link
Copy Markdown
Contributor Author

@MohamedM216 MohamedM216 Mar 30, 2026

Choose a reason for hiding this comment

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

the PUT method is not allowed

Task<WriteResult<TokenEntry>> Login(CancellationToken ct);
Task<WriteResult<TokenEntry>> Login();
Task<WriteResult<TokenEntry>> Login(WriteOptions q, CancellationToken ct = default);
Task<WriteResult<TokenEntry>> Login(string AuthMethod, string BearerToken, WriteOptions writeOptions, CancellationToken ct = default);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use lowercase for argument names:

Suggested change
Task<WriteResult<TokenEntry>> Login(string AuthMethod, string BearerToken, WriteOptions writeOptions, CancellationToken ct = default);
Task<WriteResult<TokenEntry>> Login(string authMethod, string bearerToken, WriteOptions writeOptions, CancellationToken ct = default);

Comment thread Consul.Test/AuthMethodTest.cs Outdated
var authMethod = await _client.AuthMethod.Create(authMethodEntry);
Assert.NotNull(authMethod.Response);

var res = await _client.AuthMethod.Login(authMethod.Response.Name, null /* the application's bearer token */, WriteOptions.Default);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@MohamedM216
Copy link
Copy Markdown
Contributor Author

MohamedM216 commented Mar 31, 2026

Should I exclude1.6 and 1.7 versions from the test?

@marcin-krystianc
Copy link
Copy Markdown
Contributor

Should I exclude1.6 and 1.7 versions from the test?

yes, please.

Comment thread Consul/AuthMethod.cs Outdated
Comment on lines 38 to 64
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we are introducing a breaking change (it is fine since we know that functionality never worked anyway), let's remove that code as it is just an unnecessary noise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changes addressed here

Copy link
Copy Markdown
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

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

I've left a comment that we can use that opportunity to remove unnecessary code and unnecessary API surface. Looks good otherwise.

Copy link
Copy Markdown
Contributor

@marcin-krystianc marcin-krystianc left a comment

Choose a reason for hiding this comment

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

👍

@marcin-krystianc marcin-krystianc merged commit 437073f into G-Research:master Apr 2, 2026
120 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants