From 4a619bf81bf2140b97a16f2d235f5718b0846e6c Mon Sep 17 00:00:00 2001 From: Daniel Tallentire Date: Mon, 20 Nov 2023 11:41:43 +0000 Subject: [PATCH 1/4] added test for service account --- .../GetUserInfo.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/Cronofy.Test/CronofyEnterpriseConnectAccountClientTests/GetUserInfo.cs b/test/Cronofy.Test/CronofyEnterpriseConnectAccountClientTests/GetUserInfo.cs index c1e1ecd..cdd97b3 100644 --- a/test/Cronofy.Test/CronofyEnterpriseConnectAccountClientTests/GetUserInfo.cs +++ b/test/Cronofy.Test/CronofyEnterpriseConnectAccountClientTests/GetUserInfo.cs @@ -5,7 +5,7 @@ internal sealed class GetUserInfo : Base { [Test] - public void CanGetUserInfoForSericeAccount() + public void CanGetUserInfoForServiceAccount() { this.Http.Stub( HttpGet @@ -13,12 +13,14 @@ public void CanGetUserInfoForSericeAccount() .RequestHeader("Authorization", "Bearer " + AccessToken) .ResponseCode(200) .ResponseBody( - @"{ + @" +{ ""sub"": ""ser_61a8b807a341fc00bee53042"", ""cronofy.type"": ""service_account"", ""cronofy.data"": { ""service_account"": { - ""provider_name"": ""exchange"" + ""provider_name"": ""exchange"", + ""domain"": ""example.org"" }, ""authorization"": { ""scope"": ""service_account/accounts/manage service_account/resources/manage"", @@ -27,7 +29,8 @@ public void CanGetUserInfoForSericeAccount() } }, ""email"": ""exchange-service-account@example.org"" -}")); +} +")); var actualUserInfo = this.Client.GetUserInfo(); var expectedUserInfo = new UserInfo @@ -38,6 +41,7 @@ public void CanGetUserInfoForSericeAccount() ServiceAccountInfo = new UserInfo.ServiceAccount { ProviderName = "exchange", + Domain = "example.org", }, AuthorizationInfo = new UserInfo.Authorization { From 276de2cc652c88078cdbab17c48573fab3447ea7 Mon Sep 17 00:00:00 2001 From: Daniel Tallentire Date: Mon, 20 Nov 2023 11:46:52 +0000 Subject: [PATCH 2/4] deserialize service account info --- src/Cronofy/Responses/UserInfoResponse.cs | 11 +++++++++-- src/Cronofy/UserInfo.cs | 22 ++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Cronofy/Responses/UserInfoResponse.cs b/src/Cronofy/Responses/UserInfoResponse.cs index c0e44d5..fa9ff56 100644 --- a/src/Cronofy/Responses/UserInfoResponse.cs +++ b/src/Cronofy/Responses/UserInfoResponse.cs @@ -79,8 +79,8 @@ internal sealed class CronofyData public ProfileResponse[] Profiles { get; set; } } - /// - /// Class for the deserialization of an authorization response. + /// + /// Class for the deserialization of a service account within a UserProfile. /// internal sealed class CronofyServiceAccount { @@ -93,6 +93,12 @@ internal sealed class CronofyServiceAccount [JsonProperty("provider_name")] public string ProviderName { get; set; } + /// + /// Gets or sets the domain name of the Service Account. + /// + [JsonProperty("domain")] + public string Domain { get; set; } + /// /// Converts the response into a . /// @@ -104,6 +110,7 @@ public UserInfo.ServiceAccount ToServiceAccount() return new UserInfo.ServiceAccount { ProviderName = this.ProviderName, + Domain = this.Domain, }; } } diff --git a/src/Cronofy/UserInfo.cs b/src/Cronofy/UserInfo.cs index eb1f145..1938be8 100644 --- a/src/Cronofy/UserInfo.cs +++ b/src/Cronofy/UserInfo.cs @@ -33,11 +33,10 @@ public class UserInfo /// Gets or sets the authorization of the account. /// /// The authorization for the account. - public Authorization AuthorizationInfo { get; set; } /// - /// Gets or sets the Service Account data. + /// Gets or sets the Service Account data. Only populated when CronofyType == "service_account". /// /// /// The Service Account data. public ServiceAccount ServiceAccountInfo { get; set; } @@ -95,7 +94,6 @@ public bool Equals(UserInfo other) public override string ToString() { return string.Format( - "<{0} Sub={1}, CronofyType={2}>, AuthorizationInfo={3}, ServiceAccountInfo={4} Email={5}", this.GetType(), this.Sub, @@ -308,10 +306,16 @@ public override string ToString() } /// - /// Class representing an authorization for an account. + /// Class representing additional information from the service account authorization. /// public sealed class ServiceAccount { + /// + /// Gets the domain that the service account relates to. + /// We may not be able to determine this, and this property is not guaranteed to be populated. + /// + public string Domain { get; internal set; } + /// /// Gets or sets the provider name of the Service Account. /// @@ -323,7 +327,7 @@ public sealed class ServiceAccount /// public override int GetHashCode() { - return this.ProviderName.GetHashCode(); + return this.ProviderName.GetHashCode() ^ this.Domain.GetHashCode(); } /// @@ -355,16 +359,18 @@ public override bool Equals(object obj) public bool Equals(ServiceAccount other) { return other != null - && this.ProviderName == other.ProviderName; + && this.ProviderName == other.ProviderName + && this.Domain == other.Domain; } /// public override string ToString() { return string.Format( - "<{0} ProviderName={1}>", + "<{0} ProviderName={1}, Domain={2}>", this.GetType(), - this.ProviderName); + this.ProviderName, + this.Domain); } } } From 227d81918315e93fb827cf347c3a359395ebbeaa Mon Sep 17 00:00:00 2001 From: Daniel Tallentire Date: Mon, 20 Nov 2023 10:25:30 +0000 Subject: [PATCH 3/4] update version and changelog --- CHANGELOG.md | 3 +++ VERSION | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fefebb..b545621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.13.3] +* Adds the `domain` property to the service account details when a `service_account` is returned in GetUserInfo. + ## [1.12.2] * Adding `GetAuthorizationUrlBuilder` and `GetEnterpriseConnectAuthorizationUrlBuilder` to the `ICronofyOAuthClient` interface. [#128] diff --git a/VERSION b/VERSION index 6b89d58..81f3632 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.12.2 +1.12.3 From 4a6ae3a6888885d9045f8b025b9b76e644460bd9 Mon Sep 17 00:00:00 2001 From: Daniel Tallentire <32207980+danieltallentire@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:20:56 +0000 Subject: [PATCH 4/4] update changelog version to correct version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b545621..3e4b7c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## [1.13.3] +## [1.12.3] * Adds the `domain` property to the service account details when a `service_account` is returned in GetUserInfo. ## [1.12.2]