Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit 3d25d7b

Browse files
committed
Update the samples to use ASOS RC1
1 parent 8113485 commit 3d25d7b

File tree

10 files changed

+126
-87
lines changed

10 files changed

+126
-87
lines changed

build/dependencies.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
<PropertyGroup>
44
<AspNetCoreVersion>1.0.0</AspNetCoreVersion>
5-
<AspNetContribOpenIdExtensionsVersion>1.0.0-alpha3-final</AspNetContribOpenIdExtensionsVersion>
6-
<AspNetContribOpenIdServerVersion>1.0.0-beta7-final</AspNetContribOpenIdServerVersion>
5+
<AspNetContribOpenIdExtensionsVersion>1.0.0-beta1-final</AspNetContribOpenIdExtensionsVersion>
6+
<AspNetContribOpenIdServerVersion>1.0.0-rc1-final</AspNetContribOpenIdServerVersion>
77
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
88
<RuntimeFrameworkVersion>1.0.0</RuntimeFrameworkVersion>
99
<SignalRVersion>0.1.0-*</SignalRVersion>

samples/Cordova/Backend/Controllers/AuthorizationController.cs

+17-21
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,21 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
9090

9191
// Create a new ClaimsIdentity containing the claims that
9292
// will be used to create an id_token, a token or a code.
93-
var identity = new ClaimsIdentity(OpenIdConnectServerDefaults.AuthenticationScheme);
94-
95-
// Copy the claims retrieved from the external identity provider
96-
// (e.g Google, Facebook, a WS-Fed provider or another OIDC server).
97-
foreach (var claim in HttpContext.User.Claims)
98-
{
99-
// Allow ClaimTypes.Name to be added in the id_token.
100-
// ClaimTypes.NameIdentifier is automatically added, even if its
101-
// destination is not defined or doesn't include "id_token".
102-
// The other claims won't be visible for the client application.
103-
if (claim.Type == ClaimTypes.Name)
104-
{
105-
claim.SetDestinations(OpenIdConnectConstants.Destinations.AccessToken,
106-
OpenIdConnectConstants.Destinations.IdentityToken);
107-
}
108-
109-
identity.AddClaim(claim);
110-
}
93+
var identity = new ClaimsIdentity(
94+
OpenIdConnectServerDefaults.AuthenticationScheme,
95+
OpenIdConnectConstants.Claims.Name,
96+
OpenIdConnectConstants.Claims.Role);
97+
98+
// Note: the "sub" claim is mandatory and an exception is thrown if this claim is missing.
99+
identity.AddClaim(
100+
new Claim(OpenIdConnectConstants.Claims.Subject, User.FindFirst(ClaimTypes.NameIdentifier).Value)
101+
.SetDestinations(OpenIdConnectConstants.Destinations.AccessToken,
102+
OpenIdConnectConstants.Destinations.IdentityToken));
103+
104+
identity.AddClaim(
105+
new Claim(OpenIdConnectConstants.Claims.Name, User.FindFirst(ClaimTypes.Name).Value)
106+
.SetDestinations(OpenIdConnectConstants.Destinations.AccessToken,
107+
OpenIdConnectConstants.Destinations.IdentityToken));
111108

112109
var application = await GetApplicationAsync(request.ClientId, cancellationToken);
113110
if (application == null)
@@ -129,7 +126,8 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
129126
// Note: this sample always grants the "openid", "email" and "profile" scopes
130127
// when they are requested by the client application: a real world application
131128
// would probably display a form allowing to select the scopes to grant.
132-
ticket.SetScopes(new[] {
129+
ticket.SetScopes(new[]
130+
{
133131
/* openid: */ OpenIdConnectConstants.Scopes.OpenId,
134132
/* email: */ OpenIdConnectConstants.Scopes.Email,
135133
/* profile: */ OpenIdConnectConstants.Scopes.Profile,
@@ -140,8 +138,6 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
140138
ticket.SetResources("resource_server");
141139

142140
// Returning a SignInResult will ask ASOS to serialize the specified identity to build appropriate tokens.
143-
// Note: you should always make sure the identities you return contain ClaimTypes.NameIdentifier claim.
144-
// In this sample, the identity always contains the name identifier returned by the external provider.
145141
return SignIn(ticket.Principal, ticket.Properties, ticket.AuthenticationScheme);
146142
}
147143

samples/Cordova/Backend/Startup.cs

+20-12
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,27 @@ public void Configure(IApplicationBuilder app)
9797
options.LogoutEndpointPath = "/connect/logout";
9898
options.TokenEndpointPath = "/connect/token";
9999

100-
// Register a new ephemeral key, that is discarded when the application
101-
// shuts down. Tokens signed using this key are automatically invalidated.
102-
// This method should only be used during development.
103-
options.SigningCredentials.AddEphemeralKey();
100+
// Note: see AuthorizationController.cs for more
101+
// information concerning ApplicationCanDisplayErrors.
102+
options.ApplicationCanDisplayErrors = true;
103+
options.AllowInsecureHttp = true;
104104

105+
// Note: to override the default access token format and use JWT, assign AccessTokenHandler:
106+
//
107+
// options.AccessTokenHandler = new JwtSecurityTokenHandler
108+
// {
109+
// InboundClaimTypeMap = new Dictionary<string, string>(),
110+
// OutboundClaimTypeMap = new Dictionary<string, string>()
111+
// };
112+
//
113+
// Note: when using JWT as the access token format, you have to register a signing key.
114+
//
115+
// You can register a new ephemeral key, that is discarded when the application shuts down.
116+
// Tokens signed using this key are automatically invalidated and thus this method
117+
// should only be used during development:
118+
//
119+
// options.SigningCredentials.AddEphemeralKey();
120+
//
105121
// On production, using a X.509 certificate stored in the machine store is recommended.
106122
// You can generate a self-signed certificate using Pluralsight's self-cert utility:
107123
// https://s3.amazonaws.com/pluralsight-free/keith-brown/samples/SelfCert.zip
@@ -115,14 +131,6 @@ public void Configure(IApplicationBuilder app)
115131
// assembly: typeof(Startup).GetTypeInfo().Assembly,
116132
// resource: "Backend.Certificate.pfx",
117133
// password: "Owin.Security.OpenIdConnect.Server");
118-
119-
// Note: see AuthorizationController.cs for more
120-
// information concerning ApplicationCanDisplayErrors.
121-
options.ApplicationCanDisplayErrors = true;
122-
options.AllowInsecureHttp = true;
123-
124-
// Note: to override the default access token format and use JWT, assign AccessTokenHandler:
125-
// options.AccessTokenHandler = new JwtSecurityTokenHandler();
126134
});
127135

128136
app.UseStaticFiles();

samples/Mvc/Mvc.Server/Controllers/AuthorizationController.cs

+17-21
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,21 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
9090

9191
// Create a new ClaimsIdentity containing the claims that
9292
// will be used to create an id_token, a token or a code.
93-
var identity = new ClaimsIdentity(OpenIdConnectServerDefaults.AuthenticationScheme);
94-
95-
// Copy the claims retrieved from the external identity provider
96-
// (e.g Google, Facebook, a WS-Fed provider or another OIDC server).
97-
foreach (var claim in HttpContext.User.Claims)
98-
{
99-
// Allow ClaimTypes.Name to be added in the id_token.
100-
// ClaimTypes.NameIdentifier is automatically added, even if its
101-
// destination is not defined or doesn't include "id_token".
102-
// The other claims won't be visible for the client application.
103-
if (claim.Type == ClaimTypes.Name)
104-
{
105-
claim.SetDestinations(OpenIdConnectConstants.Destinations.AccessToken,
106-
OpenIdConnectConstants.Destinations.IdentityToken);
107-
}
108-
109-
identity.AddClaim(claim);
110-
}
93+
var identity = new ClaimsIdentity(
94+
OpenIdConnectServerDefaults.AuthenticationScheme,
95+
OpenIdConnectConstants.Claims.Name,
96+
OpenIdConnectConstants.Claims.Role);
97+
98+
// Note: the "sub" claim is mandatory and an exception is thrown if this claim is missing.
99+
identity.AddClaim(
100+
new Claim(OpenIdConnectConstants.Claims.Subject, User.FindFirst(ClaimTypes.NameIdentifier).Value)
101+
.SetDestinations(OpenIdConnectConstants.Destinations.AccessToken,
102+
OpenIdConnectConstants.Destinations.IdentityToken));
103+
104+
identity.AddClaim(
105+
new Claim(OpenIdConnectConstants.Claims.Name, User.FindFirst(ClaimTypes.Name).Value)
106+
.SetDestinations(OpenIdConnectConstants.Destinations.AccessToken,
107+
OpenIdConnectConstants.Destinations.IdentityToken));
111108

112109
var application = await GetApplicationAsync(request.ClientId, cancellationToken);
113110
if (application == null)
@@ -129,7 +126,8 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
129126
// Note: this sample always grants the "openid", "email" and "profile" scopes
130127
// when they are requested by the client application: a real world application
131128
// would probably display a form allowing to select the scopes to grant.
132-
ticket.SetScopes(new[] {
129+
ticket.SetScopes(new[]
130+
{
133131
/* openid: */ OpenIdConnectConstants.Scopes.OpenId,
134132
/* email: */ OpenIdConnectConstants.Scopes.Email,
135133
/* profile: */ OpenIdConnectConstants.Scopes.Profile,
@@ -140,8 +138,6 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
140138
ticket.SetResources("resource_server");
141139

142140
// Returning a SignInResult will ask ASOS to serialize the specified identity to build appropriate tokens.
143-
// Note: you should always make sure the identities you return contain ClaimTypes.NameIdentifier claim.
144-
// In this sample, the identity always contains the name identifier returned by the external provider.
145141
return SignIn(ticket.Principal, ticket.Properties, ticket.AuthenticationScheme);
146142
}
147143

samples/Mvc/Mvc.Server/Startup.cs

+20-12
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,27 @@ public void Configure(IApplicationBuilder app)
9898
options.TokenEndpointPath = "/connect/token";
9999
options.UserinfoEndpointPath = "/connect/userinfo";
100100

101-
// Register a new ephemeral key, that is discarded when the application
102-
// shuts down. Tokens signed using this key are automatically invalidated.
103-
// This method should only be used during development.
104-
options.SigningCredentials.AddEphemeralKey();
101+
// Note: see AuthorizationController.cs for more
102+
// information concerning ApplicationCanDisplayErrors.
103+
options.ApplicationCanDisplayErrors = true;
104+
options.AllowInsecureHttp = true;
105105

106+
// Note: to override the default access token format and use JWT, assign AccessTokenHandler:
107+
//
108+
// options.AccessTokenHandler = new JwtSecurityTokenHandler
109+
// {
110+
// InboundClaimTypeMap = new Dictionary<string, string>(),
111+
// OutboundClaimTypeMap = new Dictionary<string, string>()
112+
// };
113+
//
114+
// Note: when using JWT as the access token format, you have to register a signing key.
115+
//
116+
// You can register a new ephemeral key, that is discarded when the application shuts down.
117+
// Tokens signed using this key are automatically invalidated and thus this method
118+
// should only be used during development:
119+
//
120+
// options.SigningCredentials.AddEphemeralKey();
121+
//
106122
// On production, using a X.509 certificate stored in the machine store is recommended.
107123
// You can generate a self-signed certificate using Pluralsight's self-cert utility:
108124
// https://s3.amazonaws.com/pluralsight-free/keith-brown/samples/SelfCert.zip
@@ -116,14 +132,6 @@ public void Configure(IApplicationBuilder app)
116132
// assembly: typeof(Startup).GetTypeInfo().Assembly,
117133
// resource: "Mvc.Server.Certificate.pfx",
118134
// password: "Owin.Security.OpenIdConnect.Server");
119-
120-
// Note: see AuthorizationController.cs for more
121-
// information concerning ApplicationCanDisplayErrors.
122-
options.ApplicationCanDisplayErrors = true;
123-
options.AllowInsecureHttp = true;
124-
125-
// Note: to override the default access token format and use JWT, assign AccessTokenHandler:
126-
// options.AccessTokenHandler = new JwtSecurityTokenHandler();
127135
});
128136

129137
app.UseStaticFiles();

samples/Postman/Controllers/AuthorizationController.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ public IActionResult Accept()
3333

3434
// Create a new ClaimsIdentity containing the claims that
3535
// will be used to create an id_token, a token or a code.
36-
var identity = new ClaimsIdentity(OpenIdConnectServerDefaults.AuthenticationScheme);
36+
var identity = new ClaimsIdentity(
37+
OpenIdConnectServerDefaults.AuthenticationScheme,
38+
OpenIdConnectConstants.Claims.Name,
39+
OpenIdConnectConstants.Claims.Role);
3740

38-
identity.AddClaim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString(),
41+
identity.AddClaim(OpenIdConnectConstants.Claims.Subject, Guid.NewGuid().ToString(),
3942
OpenIdConnectConstants.Destinations.AccessToken,
4043
OpenIdConnectConstants.Destinations.IdentityToken);
4144

42-
identity.AddClaim(ClaimTypes.Name, "Bob le Bricoleur",
45+
identity.AddClaim(OpenIdConnectConstants.Claims.Name, "Bob le Bricoleur",
4346
OpenIdConnectConstants.Destinations.AccessToken,
4447
OpenIdConnectConstants.Destinations.IdentityToken);
4548

samples/Postman/Providers/AuthorizationProvider.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,16 @@ public override Task HandleTokenRequest(HandleTokenRequestContext context)
110110

111111
// Create a new ClaimsIdentity containing the claims that
112112
// will be used to create an id_token and/or an access token.
113-
var identity = new ClaimsIdentity(OpenIdConnectServerDefaults.AuthenticationScheme);
113+
var identity = new ClaimsIdentity(
114+
OpenIdConnectServerDefaults.AuthenticationScheme,
115+
OpenIdConnectConstants.Claims.Name,
116+
OpenIdConnectConstants.Claims.Role);
114117

115-
identity.AddClaim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString(),
118+
identity.AddClaim(OpenIdConnectConstants.Claims.Subject, Guid.NewGuid().ToString(),
116119
OpenIdConnectConstants.Destinations.AccessToken,
117120
OpenIdConnectConstants.Destinations.IdentityToken);
118121

119-
identity.AddClaim(ClaimTypes.Name, "Bob le Bricoleur",
122+
identity.AddClaim(OpenIdConnectConstants.Claims.Name, "Bob le Bricoleur",
120123
OpenIdConnectConstants.Destinations.AccessToken,
121124
OpenIdConnectConstants.Destinations.IdentityToken);
122125

samples/Postman/Startup.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,22 @@ public void Configure(IApplicationBuilder app)
3838
options.TokenEndpointPath = "/connect/token";
3939
options.AllowInsecureHttp = true;
4040

41-
// Register a new ephemeral key, that is discarded when the application
42-
// shuts down. Tokens signed using this key are automatically invalidated.
43-
// This method should only be used during development.
44-
options.SigningCredentials.AddEphemeralKey();
45-
41+
// Note: to override the default access token format and use JWT, assign AccessTokenHandler:
42+
//
43+
// options.AccessTokenHandler = new JwtSecurityTokenHandler
44+
// {
45+
// InboundClaimTypeMap = new Dictionary<string, string>(),
46+
// OutboundClaimTypeMap = new Dictionary<string, string>()
47+
// };
48+
//
49+
// Note: when using JWT as the access token format, you have to register a signing key.
50+
//
51+
// You can register a new ephemeral key, that is discarded when the application shuts down.
52+
// Tokens signed using this key are automatically invalidated and thus this method
53+
// should only be used during development:
54+
//
55+
// options.SigningCredentials.AddEphemeralKey();
56+
//
4657
// On production, using a X.509 certificate stored in the machine store is recommended.
4758
// You can generate a self-signed certificate using Pluralsight's self-cert utility:
4859
// https://s3.amazonaws.com/pluralsight-free/keith-brown/samples/SelfCert.zip

samples/SignalR/HelloSignalR/Providers/AuthorizationProvider.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ public override Task HandleTokenRequest(HandleTokenRequestContext context)
5757
return Task.FromResult(0);
5858
}
5959

60-
var identity = new ClaimsIdentity(context.Options.AuthenticationScheme);
60+
var identity = new ClaimsIdentity(
61+
context.Options.AuthenticationScheme,
62+
OpenIdConnectConstants.Claims.Name,
63+
OpenIdConnectConstants.Claims.Role);
6164

62-
identity.AddClaim(ClaimTypes.NameIdentifier, user.Id,
65+
identity.AddClaim(OpenIdConnectConstants.Claims.Subject, user.Id,
6366
OpenIdConnectConstants.Destinations.AccessToken,
6467
OpenIdConnectConstants.Destinations.IdentityToken);
6568

66-
identity.AddClaim(ClaimTypes.Name, user.UserName,
69+
identity.AddClaim(OpenIdConnectConstants.Claims.Name, user.UserName,
6770
OpenIdConnectConstants.Destinations.AccessToken,
6871
OpenIdConnectConstants.Destinations.IdentityToken);
6972

samples/SignalR/HelloSignalR/Startup.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,22 @@ public void Configure(IApplicationBuilder app)
5050
options.TokenEndpointPath = "/connect/token";
5151
options.AllowInsecureHttp = true;
5252

53-
// Register a new ephemeral key, that is discarded when the application
54-
// shuts down. Tokens signed using this key are automatically invalidated.
55-
// This method should only be used during development.
56-
options.SigningCredentials.AddEphemeralKey();
57-
53+
// Note: to override the default access token format and use JWT, assign AccessTokenHandler:
54+
//
55+
// options.AccessTokenHandler = new JwtSecurityTokenHandler
56+
// {
57+
// InboundClaimTypeMap = new Dictionary<string, string>(),
58+
// OutboundClaimTypeMap = new Dictionary<string, string>()
59+
// };
60+
//
61+
// Note: when using JWT as the access token format, you have to register a signing key.
62+
//
63+
// You can register a new ephemeral key, that is discarded when the application shuts down.
64+
// Tokens signed using this key are automatically invalidated and thus this method
65+
// should only be used during development:
66+
//
67+
// options.SigningCredentials.AddEphemeralKey();
68+
//
5869
// On production, using a X.509 certificate stored in the machine store is recommended.
5970
// You can generate a self-signed certificate using Pluralsight's self-cert utility:
6071
// https://s3.amazonaws.com/pluralsight-free/keith-brown/samples/SelfCert.zip

0 commit comments

Comments
 (0)