Skip to content

Commit cd04cd5

Browse files
committed
Moved key controller out of the SCIM library
1 parent 10cd7ff commit cd04cd5

File tree

3 files changed

+96
-45
lines changed

3 files changed

+96
-45
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.IdentityModel.Tokens;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IdentityModel.Tokens.Jwt;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Microsoft.SCIM.WebHostSample.Controllers
11+
{
12+
// Controller for generating a bearer token for authorization during testing.
13+
// This is not meant to replace proper Oauth for authentication purposes.
14+
[Route(ServiceConstants.RouteToken)]
15+
[ApiController]
16+
public class KeyController : ControllerBase
17+
{
18+
private const int TokenLifetimeInMins = 120;
19+
20+
private static string GenerateJSONWebToken()
21+
{
22+
SymmetricSecurityKey securityKey =
23+
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(ServiceConstants.TokenIssuer));
24+
SigningCredentials credentials =
25+
new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
26+
27+
DateTime startTime = DateTime.UtcNow;
28+
DateTime expiryTime = startTime.AddMinutes(KeyController.TokenLifetimeInMins);
29+
30+
JwtSecurityToken token =
31+
new JwtSecurityToken(
32+
ServiceConstants.TokenIssuer,
33+
ServiceConstants.TokenAudience,
34+
null,
35+
notBefore: startTime,
36+
expires: expiryTime,
37+
signingCredentials: credentials);
38+
39+
string result = new JwtSecurityTokenHandler().WriteToken(token);
40+
return result;
41+
}
42+
43+
[HttpGet]
44+
public ActionResult Get()
45+
{
46+
string tokenString = KeyController.GenerateJSONWebToken();
47+
return this.Ok(new { token = tokenString });
48+
}
49+
50+
}
51+
}

Microsoft.SCIM.WebHostSample/Microsoft.SCIM.WebHostSample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>

Microsoft.SystemForCrossDomainIdentityManagement/Service/Controllers/TokenController.cs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,48 @@ namespace Microsoft.SCIM
1111
using Microsoft.AspNetCore.Mvc;
1212
using Microsoft.IdentityModel.Tokens;
1313

14-
// Controller for generating a bearer token for authorization during testing.
15-
// This is not meant to replace proper Oauth for authentication purposes.
16-
[Route(ServiceConstants.RouteToken)]
17-
[ApiController]
18-
public class KeyController : ControllerTemplate
19-
{
20-
private const int TokenLifetimeInMins = 120;
21-
22-
public KeyController(IProvider provider, IMonitor monitor)
23-
: base(provider, monitor)
24-
{
25-
}
26-
27-
private static string GenerateJSONWebToken()
28-
{
29-
SymmetricSecurityKey securityKey =
30-
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(ServiceConstants.TokenIssuer));
31-
SigningCredentials credentials =
32-
new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
33-
34-
DateTime startTime = DateTime.UtcNow;
35-
DateTime expiryTime = startTime.AddMinutes(KeyController.TokenLifetimeInMins);
36-
37-
JwtSecurityToken token =
38-
new JwtSecurityToken(
39-
ServiceConstants.TokenIssuer,
40-
ServiceConstants.TokenAudience,
41-
null,
42-
notBefore: startTime,
43-
expires: expiryTime,
44-
signingCredentials: credentials);
45-
46-
string result = new JwtSecurityTokenHandler().WriteToken(token);
47-
return result;
48-
}
49-
50-
[HttpGet]
51-
public ActionResult Get()
52-
{
53-
string tokenString = KeyController.GenerateJSONWebToken();
54-
return this.Ok(new { token = tokenString });
55-
}
56-
57-
}
14+
//// Controller for generating a bearer token for authorization during testing.
15+
//// This is not meant to replace proper Oauth for authentication purposes.
16+
//[Route(ServiceConstants.RouteToken)]
17+
//[ApiController]
18+
//public class KeyController : ControllerTemplate
19+
//{
20+
// private const int TokenLifetimeInMins = 120;
21+
22+
// public KeyController(IProvider provider, IMonitor monitor)
23+
// : base(provider, monitor)
24+
// {
25+
// }
26+
27+
// private static string GenerateJSONWebToken()
28+
// {
29+
// SymmetricSecurityKey securityKey =
30+
// new SymmetricSecurityKey(Encoding.UTF8.GetBytes(ServiceConstants.TokenIssuer));
31+
// SigningCredentials credentials =
32+
// new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
33+
34+
// DateTime startTime = DateTime.UtcNow;
35+
// DateTime expiryTime = startTime.AddMinutes(KeyController.TokenLifetimeInMins);
36+
37+
// JwtSecurityToken token =
38+
// new JwtSecurityToken(
39+
// ServiceConstants.TokenIssuer,
40+
// ServiceConstants.TokenAudience,
41+
// null,
42+
// notBefore: startTime,
43+
// expires: expiryTime,
44+
// signingCredentials: credentials);
45+
46+
// string result = new JwtSecurityTokenHandler().WriteToken(token);
47+
// return result;
48+
// }
49+
50+
// [HttpGet]
51+
// public ActionResult Get()
52+
// {
53+
// string tokenString = KeyController.GenerateJSONWebToken();
54+
// return this.Ok(new { token = tokenString });
55+
// }
56+
57+
//}
5858
}

0 commit comments

Comments
 (0)