-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added OpenIdConnect authentication and JWT token parsing to retrieve …
…the user data.
- Loading branch information
Showing
16 changed files
with
196 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.IdentityModel.Tokens.Jwt; | ||
using BMI.Models; | ||
|
||
namespace BMI.Authorisation | ||
{ | ||
public interface ITokenHandler | ||
{ | ||
JwtSecurityToken GetJwtSecurityToken(string tokenId); | ||
bool IsAuthorised(JwtSecurityToken jwtToken); | ||
UserDetails GetUserDetailsFromClaims(JwtSecurityToken jwtToken); | ||
string GetUserName(JwtSecurityToken jwtToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.IdentityModel.Tokens.Jwt; | ||
using System.Linq; | ||
using BMI.Models; | ||
|
||
namespace BMI.Authorisation | ||
{ | ||
public class TokenHandler : ITokenHandler | ||
{ | ||
public JwtSecurityToken GetJwtSecurityToken(string tokenId) | ||
{ | ||
var handler = new JwtSecurityTokenHandler(); | ||
return handler.ReadToken(tokenId) as JwtSecurityToken; | ||
} | ||
|
||
public bool IsAuthorised(JwtSecurityToken jwtToken) | ||
{ | ||
var access = GetClaim(jwtToken, "extension_Access"); | ||
|
||
return access.Equals("True"); | ||
} | ||
|
||
public UserDetails GetUserDetailsFromClaims(JwtSecurityToken jwtToken) | ||
{ | ||
return new UserDetails | ||
{ | ||
Height = double.Parse(GetClaim(jwtToken, "extension_Height")), | ||
Weight = double.Parse(GetClaim(jwtToken, "extension_Weight")) | ||
}; | ||
} | ||
|
||
public string GetUserName(JwtSecurityToken jwtToken) | ||
{ | ||
return GetClaim(jwtToken, "family_name"); | ||
} | ||
|
||
private static string GetClaim( | ||
JwtSecurityToken jwtToken, | ||
string claimType) | ||
{ | ||
return jwtToken.Claims.First(claim => claim.Type == claimType).Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace BMI | ||
namespace BMI.Reporting | ||
{ | ||
public class BmiCategory | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
<h4>@ViewData["Result"]</h4> | ||
|
||
<h4>Population BMI Report</h4> | ||
<br /> | ||
<table class="table table-striped table-bordered"> | ||
<thead> | ||
<tr> | ||
<th> | ||
Category | ||
</th> | ||
<th> | ||
Count | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var item in (List<ReportModel>)ViewData["PopulationReport"]) | ||
{ | ||
<tr> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Category) | ||
</td> | ||
<td> | ||
@Html.DisplayFor(modelItem => item.Count) | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
<h4> You rank in @ViewData["UsersRanking"]% percentile of the population.</h4> |
Oops, something went wrong.