Skip to content

Commit

Permalink
Merge pull request #131 from cronofy/add-service-account-domain
Browse files Browse the repository at this point in the history
Add service account domain property to service account user info.
  • Loading branch information
Nevett committed Nov 22, 2023
2 parents c9455f8 + 4a6ae3a commit 6a2d4a5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.12.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]
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.2
1.12.3
11 changes: 9 additions & 2 deletions src/Cronofy/Responses/UserInfoResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ internal sealed class CronofyData
public ProfileResponse[] Profiles { get; set; }
}

/// <summary>
/// Class for the deserialization of an authorization response.
/// <summary>
/// Class for the deserialization of a service account within a UserProfile.
/// </summary>
internal sealed class CronofyServiceAccount
{
Expand All @@ -93,6 +93,12 @@ internal sealed class CronofyServiceAccount
[JsonProperty("provider_name")]
public string ProviderName { get; set; }

/// <summary>
/// Gets or sets the domain name of the Service Account.
/// </summary>
[JsonProperty("domain")]
public string Domain { get; set; }

/// <summary>
/// Converts the response into a <see cref="Cronofy.Account"/>.
/// </summary>
Expand All @@ -104,6 +110,7 @@ public UserInfo.ServiceAccount ToServiceAccount()
return new UserInfo.ServiceAccount
{
ProviderName = this.ProviderName,
Domain = this.Domain,
};
}
}
Expand Down
22 changes: 14 additions & 8 deletions src/Cronofy/UserInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ public class UserInfo
/// Gets or sets the authorization of the account.
/// </summary>
/// <value> The authorization for the account.</value>

public Authorization AuthorizationInfo { get; set; }

/// <summary>
/// Gets or sets the Service Account data.
/// Gets or sets the Service Account data. Only populated when CronofyType == "service_account".
/// </summary>
/// <value> /// The Service Account data.</value>
public ServiceAccount ServiceAccountInfo { get; set; }
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -308,10 +306,16 @@ public override string ToString()
}

/// <summary>
/// Class representing an authorization for an account.
/// Class representing additional information from the service account authorization.
/// </summary>
public sealed class ServiceAccount
{
/// <summary>
/// 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.
/// </summary>
public string Domain { get; internal set; }

/// <summary>
/// Gets or sets the provider name of the Service Account.
/// </summary>
Expand All @@ -323,7 +327,7 @@ public sealed class ServiceAccount
/// <inheritdoc/>
public override int GetHashCode()
{
return this.ProviderName.GetHashCode();
return this.ProviderName.GetHashCode() ^ this.Domain.GetHashCode();
}

/// <inheritdoc/>
Expand Down Expand Up @@ -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;
}

/// <inheritdoc/>
public override string ToString()
{
return string.Format(
"<{0} ProviderName={1}>",
"<{0} ProviderName={1}, Domain={2}>",
this.GetType(),
this.ProviderName);
this.ProviderName,
this.Domain);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
internal sealed class GetUserInfo : Base
{
[Test]
public void CanGetUserInfoForSericeAccount()
public void CanGetUserInfoForServiceAccount()
{
this.Http.Stub(
HttpGet
.Url("https://api.cronofy.com/v1/userinfo")
.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"",
Expand All @@ -27,7 +29,8 @@ public void CanGetUserInfoForSericeAccount()
}
},
""email"": ""[email protected]""
}"));
}
"));

var actualUserInfo = this.Client.GetUserInfo();
var expectedUserInfo = new UserInfo
Expand All @@ -38,6 +41,7 @@ public void CanGetUserInfoForSericeAccount()
ServiceAccountInfo = new UserInfo.ServiceAccount
{
ProviderName = "exchange",
Domain = "example.org",
},
AuthorizationInfo = new UserInfo.Authorization
{
Expand Down

0 comments on commit 6a2d4a5

Please sign in to comment.