From 8c367a9cecb8b58e86147d5d9a4981b3da92d15f Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Mon, 1 Mar 2021 16:32:53 +0000 Subject: [PATCH 1/3] Update get token response to include auth info --- .../GetUserAccessToken/GetUserAccessTokenResponse.cs | 3 +++ .../GetUserAccessToken/GetUserAccessTokenApiTests.cs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs b/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs index 469f8300881..9eefa7e344a 100644 --- a/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs +++ b/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs @@ -19,5 +19,8 @@ public class GetUserAccessTokenResponse : ResponseBase [DataMember(Name ="type")] public string Type { get; set; } + + [DataMember(Name = "authentication")] + public AuthenticateResponse Authentication { get; set; } } } diff --git a/tests/Tests/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenApiTests.cs b/tests/Tests/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenApiTests.cs index d63caebc922..bf626ea6faa 100644 --- a/tests/Tests/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenApiTests.cs +++ b/tests/Tests/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenApiTests.cs @@ -7,6 +7,8 @@ using Elasticsearch.Net; using FluentAssertions; using Nest; +using Tests.Configuration; +using Tests.Core.Extensions; using Tests.Framework.EndpointTests; using Tests.Framework.EndpointTests.TestState; using static Elastic.Elasticsearch.Ephemeral.ClusterAuthentication; @@ -63,6 +65,13 @@ protected override void ExpectResponse(GetUserAccessTokenResponse response) response.Type.Should().NotBeNullOrEmpty().And.Be("Bearer"); response.ExpiresIn.Should().BeGreaterThan(0); response.Scope.Should().Be("full"); + + if (TestConfiguration.Instance.InRange(">=7.11.0")) + { + response.Authentication.Should().NotBeNull(); + response.Authentication.Username.Should().NotBeNullOrEmpty(); + response.Authentication.Roles.Count.Should().BeGreaterThan(0); + } } } From 5ce304718730c1e49b722b4bcf74890fd5ea7fd4 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Wed, 3 Mar 2021 09:23:15 +0000 Subject: [PATCH 2/3] Update token response --- .../GetUserAccessTokenResponse.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs b/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs index 9eefa7e344a..50face03907 100644 --- a/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs +++ b/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs @@ -21,6 +21,35 @@ public class GetUserAccessTokenResponse : ResponseBase public string Type { get; set; } [DataMember(Name = "authentication")] - public AuthenticateResponse Authentication { get; set; } + public Authentication Authentication { get; set; } + } + + public class Authentication : ResponseBase + { + [DataMember(Name = "email")] + public string Email { get; internal set; } + + [DataMember(Name = "full_name")] + public string FullName { get; internal set; } + + [DataMember(Name = "metadata")] + public IReadOnlyDictionary Metadata { get; internal set; } + = EmptyReadOnly.Dictionary; + + [DataMember(Name = "roles")] + public IReadOnlyCollection Roles { get; internal set; } + = EmptyReadOnly.Collection; + + [DataMember(Name = "username")] + public string Username { get; internal set; } + + [DataMember(Name = "authentication_realm")] + public RealmInfo AuthenticationRealm { get; internal set; } + + [DataMember(Name = "lookup_realm")] + public RealmInfo LookupRealm { get; internal set; } + + [DataMember(Name = "authentication_type")] + public string AuthenticationType { get; internal set; } } } From 711b3266f4f5de3905a2ef2b9c960cef3a3d8788 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Wed, 3 Mar 2021 09:35:11 +0000 Subject: [PATCH 3/3] Update response --- .../GetUserAccessTokenResponse.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs b/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs index 50face03907..07fd708ff91 100644 --- a/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs +++ b/src/Nest/XPack/Security/User/GetUserAccessToken/GetUserAccessTokenResponse.cs @@ -2,7 +2,9 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information +using System.Collections.Generic; using System.Runtime.Serialization; +using Elasticsearch.Net; namespace Nest { @@ -24,7 +26,7 @@ public class GetUserAccessTokenResponse : ResponseBase public Authentication Authentication { get; set; } } - public class Authentication : ResponseBase + public class Authentication { [DataMember(Name = "email")] public string Email { get; internal set; } @@ -44,12 +46,21 @@ public class Authentication : ResponseBase public string Username { get; internal set; } [DataMember(Name = "authentication_realm")] - public RealmInfo AuthenticationRealm { get; internal set; } + public AuthenticationRealmInfo AuthenticationRealm { get; internal set; } [DataMember(Name = "lookup_realm")] - public RealmInfo LookupRealm { get; internal set; } + public AuthenticationRealmInfo LookupRealm { get; internal set; } [DataMember(Name = "authentication_type")] public string AuthenticationType { get; internal set; } } + + public class AuthenticationRealmInfo + { + [DataMember(Name = "name")] + public string Name { get; internal set; } + + [DataMember(Name = "type")] + public string Type { get; internal set; } + } }