Configuring angular-oidc-client with the new functional APIs
The latest versions of Angular have introduced new functional APIs for configuring applications. These APIs include functional guards, new APIs for the HTTP client, and standalone components like EnvironmentProviders. With these new APIs, developers have more flexibility in configuring their Angular applications.
In line with these updates, the latest version of angular-auth-oidc-client (v16.0.0) has also been released. This version includes new functionality to support the new Angular APIs. In this article, Tim Deschryver explains how to configure angular-oidc-client using the new functional APIs.
To start, instead of using the AuthModule, developers can now use the provideAuth
method to configure the authentication flow. This method takes the same configuration options as the AuthModule's config object.
Additionally, to add the user's access token to HTTP requests, developers can now use the authInterceptor
function. Previously, they had to use the HTTP_INTERCEPTORS
injection token to register the AuthInterceptor
class provided by the library. Using authInterceptor
simplifies the process.
For more details and code examples, refer to the original blog post by Tim Deschryver.