Dangl.Identity Client Libraries
Dangl.Identity is an OpenID / OAuth2 capable server that offers single sign on functionalities.
It's primary is available at https://identity.dangl-it.com with a fallback at https://identity.dangl-it.de.
It works with all OpenID Connect compatible clients and it's configuration is available here.
The preview is available at https://identity-dev.dangl-it.com.
The Dangl.Identity.Client libraries offer specialised classes and utilities that make integrating and connecting with Dangl.Identity easy.
Default Configuration
By default, the identity servers are expected to be reachable at https://identity.dangl-it.com
and https://identity.dangl-it.de
. Fallback happens automatically to the latter one if the former is unreachable.
Dangl.Identity.Client
This project includes the DanglIdentityLoginHandler
that offers JWT / OAuth2 login and refresh functionalities for clients that have the ResourceOwnerPasswordGrant
enabled.
The DanglIdentityClientCredentialsLoginHandler
can be used with clients that have the ClientCredentials
grant enabled, for example in server-side applications.
Both login handlers require an instance of HttpClient
to be injected at creation. It is advised that the HttpClientFactory
from the Microsoft.Extensions.Http
package is used
to efficiently manage the lifetime of HttpClient
instances.
Angular Client
Web applications that use the integrated Dangl.Identity JWT endpoints from the Dangl.Identity.Client.MVC
package can use the @dangl/angular-dangl-identity-client
npm package.
This package offers a generated client for the Dangl.Identity JWT endpoints and manages local storage of JWT tokens. The client assumes that the endpoint is available on the current host, otherwise it uses an injection parameter:
@Optional() @Inject(DANGL_IDENTITY_CLIENT_API_BASE_URL) baseUrl?: string
Install Dependencies
The package requires a peer dependency of @auth0/angular-jwt
which must be manually
installed in the consuming project.
Reference Module
Just import the DanglIdentityModule
in your app.
import { AppComponent } from './app.component';
import { DanglIdentityModule } from '@dangl/angular-dangl-identity-client';
@NgModule({
imports: [
DanglIdentityModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
Login / Logout
Here's an example login functionality:
import { AuthenticationService,
AuthenticationMessenger } from '@dangl/angular-dangl-identity-client';
this.isAuthenticatedSubscription = this.authenticationMessenger
.isAuthenticated
.subscribe(ia => this.isAuthenticated = ia);
login() {
this.requestEnRoute = true;
this.authenticationService
.loginWithToken(this.credentials.identifier, this.credentials.password)
.subscribe(r => {
this.requestEnRoute = false;
if (r) {
this.showLoginError = false;
this.errorCount = 0;
this.router.navigateByUrl('/');
} else {
this.showLoginError = true;
this.errorCount++;
}
});
}
AuthenticationMessenger
The AuthenticationMessenger
class can be used to watch for changes in the authentication. It will automatically try to refresh the token if a refresh token
is present and the current token is expired on load.