Skip to content

Commit ff63ef0

Browse files
committed
Minor fixes
1 parent 8fa384c commit ff63ef0

10 files changed

+44
-10
lines changed

EXPLANATION.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static IEnumerable<Client> GetClients()
99
// Clients credentials.
1010
return new List<Client>
1111
{
12-
// http://docs.identityserver.io/en/dev/reference/client.html.
12+
// http://docs.identityserver.io/en/release/reference/client.html.
1313
new Client
1414
{
1515
ClientId = "AngularSPA",
@@ -105,6 +105,21 @@ services.AddDbContext<ApplicationDbContext>(options =>
105105
services.AddIdentity<ApplicationUser, IdentityRole>()
106106
.AddEntityFrameworkStores<ApplicationDbContext>()
107107
.AddDefaultTokenProviders();
108+
109+
// Identity options.
110+
services.Configure<IdentityOptions>(options =>
111+
{
112+
// Password settings.
113+
options.Password.RequireDigit = true;
114+
options.Password.RequiredLength = 8;
115+
options.Password.RequireNonAlphanumeric = false;
116+
options.Password.RequireUppercase = true;
117+
options.Password.RequireLowercase = false;
118+
// Lockout settings.
119+
options.Lockout.AllowedForNewUsers = true;
120+
options.Lockout.MaxFailedAccessAttempts = 3;
121+
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromDays(1);
122+
});
108123
```
109124
and add Identity to the pipeline:
110125
```C#
@@ -333,6 +348,10 @@ public startupTokenRefresh(): void {
333348
}
334349
);
335350
});
351+
} else {
352+
// Revokes tokens.
353+
this.revokeToken();
354+
this.revokeRefreshToken();
336355
}
337356
}
338357

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ Get the [Changelog](https://github.com/robisim74/AngularSPAWebAPI/blob/master/CH
99
[Live example](http://angularspawebapi.azurewebsites.net) and its [explanation](https://github.com/robisim74/AngularSPAWebAPI/blob/master/EXPLANATION.md).
1010

1111
**Links**
12-
- [Talk to a remote server with an HTTP Client](https://angular.io/docs/ts/latest/guide/server-communication.html)
13-
- [IdentityServer4](https://identityserver4.readthedocs.io) | [Protecting an API using Passwords](http://docs.identityserver.io/en/dev/quickstarts/2_resource_owner_passwords.html)
14-
- [ASP.NET Core - Security](https://docs.asp.net/en/latest/security/index.html) | [Role based Authorization](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/roles)
12+
- [IdentityServer4](https://identityserver4.readthedocs.io/en/release/) | [Protecting an API using Passwords](https://identityserver4.readthedocs.io/en/release/quickstarts/2_resource_owner_passwords.html)
13+
- [ASP.NET Core - Security](https://docs.microsoft.com/en-us/aspnet/core/security/) | [Role based Authorization](https://docs.microsoft.com/en-us/aspnet/core/security/authorization/roles)
1514

16-
For more complex scenarios, where web services are required by more than one application or third-party applications,
17-
you should consider to use an OpenID Connect flow.
15+
> ROPC grant requires the use of SSL.
16+
17+
> For more complex scenarios, where web services are required by more than one application or third-party applications,
18+
you should use an OpenID Connect flow.
1819

1920
**Links**
2021
- [IDENTITYSERVER4, WEB API AND ANGULAR IN A SINGLE ASP.NET CORE PROJECT](https://damienbod.com/2016/10/01/identityserver4-webapi-and-angular2-in-a-single-asp-net-core-project/)

src/AngularSPAWebAPI/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static IEnumerable<Client> GetClients()
3434
// Clients credentials.
3535
return new List<Client>
3636
{
37-
// http://docs.identityserver.io/en/dev/reference/client.html.
37+
// http://docs.identityserver.io/en/release/reference/client.html.
3838
new Client
3939
{
4040
ClientId = "AngularSPA",

src/AngularSPAWebAPI/Startup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Microsoft.Extensions.Logging;
1313
using Swashbuckle.AspNetCore.Swagger;
14+
using System;
1415
using System.Linq;
1516
using System.Security.Cryptography.X509Certificates;
1617

@@ -51,6 +52,10 @@ public void ConfigureServices(IServiceCollection services)
5152
options.Password.RequireNonAlphanumeric = false;
5253
options.Password.RequireUppercase = true;
5354
options.Password.RequireLowercase = false;
55+
// Lockout settings.
56+
options.Lockout.AllowedForNewUsers = true;
57+
options.Lockout.MaxFailedAccessAttempts = 3;
58+
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromDays(1);
5459
});
5560

5661
services.AddMvc();

src/AngularSPAWebAPI/app/services/authentication.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ import { BrowserStorage } from './browser-storage.service';
138138
}
139139
);
140140
});
141+
} else {
142+
// Revokes tokens.
143+
this.revokeToken();
144+
this.revokeRefreshToken();
141145
}
142146
}
143147

@@ -317,7 +321,12 @@ import { BrowserStorage } from './browser-storage.service';
317321
}
318322

319323
private getUser(): User {
320-
return this.browserStorage.get("user_info") ? JSON.parse(this.browserStorage.get("user_info")) : new User();
324+
if (this.tokenNotExpired() && this.browserStorage.get("user_info")) {
325+
return JSON.parse(this.browserStorage.get("user_info"));;
326+
}
327+
// Removes user's info if the token is expired.
328+
this.browserStorage.remove("user_info");
329+
return new User();
321330
}
322331

323332
private storeUser(user: User): void {

src/AngularSPAWebAPI/wwwroot/dist/app-aot.b4b7df437ce2d95edb48.bundle.js renamed to src/AngularSPAWebAPI/wwwroot/dist/app-aot.d98b3366a9f569342f20.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AngularSPAWebAPI/wwwroot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
</head>
1515
<body>
1616
<app-component>Loading...</app-component>
17-
<script type="text/javascript" src="dist/app-aot.b4b7df437ce2d95edb48.bundle.js"></script></body>
17+
<script type="text/javascript" src="dist/app-aot.d98b3366a9f569342f20.bundle.js"></script></body>
1818
</html>

0 commit comments

Comments
 (0)