Skip to content

Commit 2c0d16b

Browse files
Merge pull request #874 from ManuelRauber/feature/date-time-provider
Feature: DateTimeProvider
2 parents 6a52616 + 3e9598d commit 2c0d16b

15 files changed

+1132
-219
lines changed

docs-src/custom-date-time-provider.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Custom DateTimeProvider
2+
3+
If your Identity Provider's clock is not synchronized, the validation of the token could fail.
4+
If the deviation is only some seconds, you can use the `AuthConfig.clockSkewInSec` setting to allow a bigger time window deviation.
5+
6+
However, you may need to adjust the base time, that is used for the token validation and make sure, that the `AuthConfig.clockSkewInSec` is still a small reasonable number, then you can implement a custom `DateTimeProvider`.
7+
8+
To do so, create a new service that derives from `DateTimeProvider`:
9+
10+
```typescript
11+
export class MyCustomDateTimeProvider extends DateTimeProvider {
12+
now(): number {
13+
// Return your custom now.
14+
return Date.now();
15+
}
16+
17+
new(): Date {
18+
// Return your custom new Date().
19+
return new Date();
20+
}
21+
}
22+
```
23+
24+
Then, override the provider via dependency injection in your application:
25+
26+
```typescript
27+
@NgModule({
28+
imports: [
29+
// etc.
30+
OAuthModule.forRoot()
31+
],
32+
providers: [
33+
{ provide: DateTimeProvider, useClass: MyCustomDateTimeProvider } // <- add this
34+
],
35+
declarations: [
36+
AppComponent,
37+
// etc.
38+
],
39+
bootstrap: [
40+
AppComponent
41+
]
42+
})
43+
export class AppModule {
44+
}
45+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<!doctype html>
2+
<html class="no-js" lang="">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="x-ua-compatible" content="ie=edge">
6+
<title>angular-oauth2-oidc</title>
7+
<meta name="description" content="">
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
10+
<link rel="icon" type="image/x-icon" href="../images/favicon.ico">
11+
<link rel="stylesheet" href="../styles/style.css">
12+
</head>
13+
<body>
14+
15+
<div class="navbar navbar-default navbar-fixed-top visible-xs">
16+
<a href="../" class="navbar-brand">angular-oauth2-oidc</a>
17+
<button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
18+
</div>
19+
20+
<div class="xs-menu menu" id="mobile-menu">
21+
<div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div> <compodoc-menu></compodoc-menu>
22+
</div>
23+
24+
<div class="container-fluid main">
25+
<div class="row main">
26+
<div class="hidden-xs menu">
27+
<compodoc-menu mode="normal"></compodoc-menu>
28+
</div>
29+
<!-- START CONTENT -->
30+
<div class="content additional-page">
31+
<div class="content-data">
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
<h1 id="custom-datetimeprovider">Custom DateTimeProvider</h1>
52+
<p>If your Identity Provider&#39;s clock is not synchronized, the validation of the token could fail.
53+
If the deviation is only some seconds, you can use the <code>AuthConfig.clockSkewInSec</code> setting to allow a bigger time window deviation.</p>
54+
<p>However, you may need to adjust the base time, that is used for the token validation and make sure, that the <code>AuthConfig.clockSkewInSec</code> is still a small reasonable number, then you can implement a custom <code>DateTimeProvider</code>.</p>
55+
<p>To do so, create a new service that derives from <code>DateTimeProvider</code>:</p>
56+
<div><pre class="line-numbers"><code class="language-typescript">export class MyCustomDateTimeProvider extends DateTimeProvider {
57+
now(): number {
58+
// Return your custom now.
59+
return Date.now();
60+
}
61+
62+
new(): Date {
63+
// Return your custom new Date().
64+
return new Date();
65+
}
66+
}</code></pre></div><p>Then, override the provider via dependency injection in your application:</p>
67+
<div><pre class="line-numbers"><code class="language-typescript">&#64;NgModule({
68+
imports: [
69+
// etc.
70+
OAuthModule.forRoot()
71+
],
72+
providers: [
73+
{ provide: DateTimeProvider, useClass: MyCustomDateTimeProvider } // &lt;- add this
74+
],
75+
declarations: [
76+
AppComponent,
77+
// etc.
78+
],
79+
bootstrap: [
80+
AppComponent
81+
]
82+
})
83+
export class AppModule {
84+
}</code></pre></div>
85+
</div><div class="search-results">
86+
<div class="has-results">
87+
<h1 class="search-results-title"><span class='search-results-count'></span> result-matching "<span class='search-query'></span>"</h1>
88+
<ul class="search-results-list"></ul>
89+
</div>
90+
<div class="no-results">
91+
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
92+
</div>
93+
</div>
94+
</div>
95+
<!-- END CONTENT -->
96+
</div>
97+
</div>
98+
99+
<script>
100+
var COMPODOC_CURRENT_PAGE_DEPTH = 1;
101+
var COMPODOC_CURRENT_PAGE_CONTEXT = 'additional-page';
102+
var COMPODOC_CURRENT_PAGE_URL = 'custom-datetimeprovider.html';
103+
var MAX_SEARCH_RESULTS = 15;
104+
</script>
105+
106+
<script src="../js/libs/custom-elements.min.js"></script>
107+
<script src="../js/libs/lit-html.js"></script>
108+
<!-- Required to polyfill modern browsers as code is ES5 for IE... -->
109+
<script src="../js/libs/custom-elements-es5-adapter.js" charset="utf-8" defer></script>
110+
<script src="../js/menu-wc.js" defer></script>
111+
112+
<script src="../js/libs/bootstrap-native.js"></script>
113+
114+
<script src="../js/libs/es6-shim.min.js"></script>
115+
<script src="../js/libs/EventDispatcher.js"></script>
116+
<script src="../js/libs/promise.min.js"></script>
117+
<script src="../js/libs/zepto.min.js"></script>
118+
119+
<script src="../js/compodoc.js"></script>
120+
121+
<script src="../js/tabs.js"></script>
122+
<script src="../js/menu.js"></script>
123+
<script src="../js/libs/clipboard.min.js"></script>
124+
<script src="../js/libs/prism.js"></script>
125+
<script src="../js/sourceCode.js"></script>
126+
<script src="../js/search/search.js"></script>
127+
<script src="../js/search/lunr.min.js"></script>
128+
<script src="../js/search/search-lunr.js"></script>
129+
<script src="../js/search/search_index.js"></script>
130+
<script src="../js/lazy-load-graphs.js"></script>
131+
132+
133+
</body>
134+
</html>

0 commit comments

Comments
 (0)