Skip to content

Commit

Permalink
Add role to profile (#179)
Browse files Browse the repository at this point in the history
* add role reponse to profile

* remove nullable reference
  • Loading branch information
kendallstrautman authored Oct 21, 2024
1 parent 1661934 commit 5ae11ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/WorkOS.net/Services/SSO/Entities/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public class Profile
[JsonProperty("last_name")]
public string LastName { get; set; }

/// <summary>
/// The User's role.
/// </summary>
[JsonProperty("role")]
public RoleResponse Role { get; set; }

/// <summary>
/// The user's groups.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/WorkOS.net/Services/_common/Entities/RoleResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace WorkOS
{
using Newtonsoft.Json;

/// <summary>
/// Represents a user's role.
/// </summary>
public class RoleResponse
{
/// <summary>
/// The slug identifier for the role.
/// </summary>
[JsonProperty("slug")]
public string Slug { get; set; }
}
}
6 changes: 6 additions & 0 deletions test/WorkOSTests/Services/SSO/SSOServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public async void TestGetProfileAndToken()
Email = "[email protected]",
FirstName = "Rick",
LastName = "Sanchez",
Role = new RoleResponse { Slug = "admin" },
Groups = new List<string>()
{
"Admins",
Expand Down Expand Up @@ -243,6 +244,8 @@ public async void TestGetProfileAndToken()
Assert.Equal(
JsonConvert.SerializeObject(mockProfile),
JsonConvert.SerializeObject(profile));
Assert.NotNull(profile.Role);
Assert.Equal("admin", profile.Role.Slug);
}

[Fact]
Expand All @@ -258,6 +261,7 @@ public async void TestGetProfile()
Email = "[email protected]",
FirstName = "Rick",
LastName = "Sanchez",
Role = new RoleResponse { Slug = "admin" },
Groups = new List<string>()
{
"Admins",
Expand Down Expand Up @@ -287,6 +291,8 @@ public async void TestGetProfile()

this.httpMock.AssertRequestWasMade(HttpMethod.Get, "/sso/profile");
this.httpMock.AssertAuthorizationBearerHeader("access_token");
Assert.NotNull(profile.Role);
Assert.Equal("admin", profile.Role.Slug);
}

[Fact]
Expand Down

0 comments on commit 5ae11ef

Please sign in to comment.