Skip to content

Feature: DateTimeProvider #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs-src/custom-date-time-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Custom DateTimeProvider

If your Identity Provider's clock is not synchronized, the validation of the token could fail.
If the deviation is only some seconds, you can use the `AuthConfig.clockSkewInSec` setting to allow a bigger time window deviation.

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`.

To do so, create a new service that derives from `DateTimeProvider`:

```typescript
export class MyCustomDateTimeProvider extends DateTimeProvider {
now(): number {
// Return your custom now.
return Date.now();
}

new(): Date {
// Return your custom new Date().
return new Date();
}
}
```

Then, override the provider via dependency injection in your application:

```typescript
@NgModule({
imports: [
// etc.
OAuthModule.forRoot()
],
providers: [
{ provide: DateTimeProvider, useClass: MyCustomDateTimeProvider } // <- add this
],
declarations: [
AppComponent,
// etc.
],
bootstrap: [
AppComponent
]
})
export class AppModule {
}
```
134 changes: 134 additions & 0 deletions docs/additional-documentation/custom-datetimeprovider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>angular-oauth2-oidc</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="icon" type="image/x-icon" href="../images/favicon.ico">
<link rel="stylesheet" href="../styles/style.css">
</head>
<body>

<div class="navbar navbar-default navbar-fixed-top visible-xs">
<a href="../" class="navbar-brand">angular-oauth2-oidc</a>
<button type="button" class="btn btn-default btn-menu ion-ios-menu" id="btn-menu"></button>
</div>

<div class="xs-menu menu" id="mobile-menu">
<div id="book-search-input" role="search"><input type="text" placeholder="Type to search"></div> <compodoc-menu></compodoc-menu>
</div>

<div class="container-fluid main">
<div class="row main">
<div class="hidden-xs menu">
<compodoc-menu mode="normal"></compodoc-menu>
</div>
<!-- START CONTENT -->
<div class="content additional-page">
<div class="content-data">



















<h1 id="custom-datetimeprovider">Custom DateTimeProvider</h1>
<p>If your Identity Provider&#39;s clock is not synchronized, the validation of the token could fail.
If the deviation is only some seconds, you can use the <code>AuthConfig.clockSkewInSec</code> setting to allow a bigger time window deviation.</p>
<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>
<p>To do so, create a new service that derives from <code>DateTimeProvider</code>:</p>
<div><pre class="line-numbers"><code class="language-typescript">export class MyCustomDateTimeProvider extends DateTimeProvider {
now(): number {
// Return your custom now.
return Date.now();
}

new(): Date {
// Return your custom new Date().
return new Date();
}
}</code></pre></div><p>Then, override the provider via dependency injection in your application:</p>
<div><pre class="line-numbers"><code class="language-typescript">&#64;NgModule({
imports: [
// etc.
OAuthModule.forRoot()
],
providers: [
{ provide: DateTimeProvider, useClass: MyCustomDateTimeProvider } // &lt;- add this
],
declarations: [
AppComponent,
// etc.
],
bootstrap: [
AppComponent
]
})
export class AppModule {
}</code></pre></div>
</div><div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> result-matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
<!-- END CONTENT -->
</div>
</div>

<script>
var COMPODOC_CURRENT_PAGE_DEPTH = 1;
var COMPODOC_CURRENT_PAGE_CONTEXT = 'additional-page';
var COMPODOC_CURRENT_PAGE_URL = 'custom-datetimeprovider.html';
var MAX_SEARCH_RESULTS = 15;
</script>

<script src="../js/libs/custom-elements.min.js"></script>
<script src="../js/libs/lit-html.js"></script>
<!-- Required to polyfill modern browsers as code is ES5 for IE... -->
<script src="../js/libs/custom-elements-es5-adapter.js" charset="utf-8" defer></script>
<script src="../js/menu-wc.js" defer></script>

<script src="../js/libs/bootstrap-native.js"></script>

<script src="../js/libs/es6-shim.min.js"></script>
<script src="../js/libs/EventDispatcher.js"></script>
<script src="../js/libs/promise.min.js"></script>
<script src="../js/libs/zepto.min.js"></script>

<script src="../js/compodoc.js"></script>

<script src="../js/tabs.js"></script>
<script src="../js/menu.js"></script>
<script src="../js/libs/clipboard.min.js"></script>
<script src="../js/libs/prism.js"></script>
<script src="../js/sourceCode.js"></script>
<script src="../js/search/search.js"></script>
<script src="../js/search/lunr.min.js"></script>
<script src="../js/search/search-lunr.js"></script>
<script src="../js/search/search_index.js"></script>
<script src="../js/lazy-load-graphs.js"></script>


</body>
</html>
Loading