Skip to content

Commit 4af3467

Browse files
damienmoulardClement-Roque
authored andcommitted
add roles management for api accessibility
1 parent 8c474e9 commit 4af3467

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

Diff for: Zenergy/Zenergy/Controllers/ApiControllers/membersController.cs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Zenergy.Controllers.ApiControllers
1515
{
16+
[Authorize]
1617
public class membersController : ApiController
1718
{
1819
private ZenergyContext db = new ZenergyContext();

Diff for: Zenergy/Zenergy/Controllers/ApiControllers/usersController.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace Zenergy.Controllers.ApiControllers
1616
{
17+
[Authorize]
1718
public class usersController : ApiController
1819
{
1920
private ZenergyContext db = new ZenergyContext();
@@ -25,14 +26,12 @@ public usersController()
2526
}
2627

2728
// GET: api/users
28-
[Authorize]
2929
public IQueryable<user> Getuser()
3030
{
3131
return db.user;
3232
}
3333

3434
// GET: api/users/5
35-
//[Authorize(Roles = "Admin")]
3635
[ResponseType(typeof(user))]
3736
public async Task<IHttpActionResult> Getuser(int id)
3837
{
@@ -55,7 +54,6 @@ public async Task<IHttpActionResult> findByMail(string userMail)
5554
{
5655
return NotFound();
5756
}
58-
5957
return Ok(user);
6058
}
6159

Diff for: Zenergy/Zenergy/Providers/ApplicationOAuthProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwner
5151
identity.AddClaim(new Claim("mail", context.UserName));
5252
identity.AddClaim(new Claim("role", "user"));
5353
identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
54-
/*
54+
5555
if (user.member != null)
5656
{
5757
identity.AddClaim(new Claim(ClaimTypes.Role, "Member"));
@@ -67,7 +67,7 @@ public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwner
6767
if (user.admin != null)
6868
{
6969
identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
70-
} */
70+
}
7171

7272
AuthenticationProperties properties = CreateProperties(user.mail);
7373
AuthenticationTicket ticket = new AuthenticationTicket(identity, properties);

0 commit comments

Comments
 (0)