In the last days, I've updated my lib
that allows to use OAuth 2 and OpenId Connect (OIDC) together with Angular 2 to
implement modern auth scenarios. In order to align with the new naming
conventions (#JustAngular) it is called angular-oauth2-oidc now. It can be downloaded via npm. Same examples showing how to use it can be found in
the npm repository. The next sections describe the new features.
The new version not only supports the
implicit flow which redirects the user to the auth server for logging in, but
also the password flow. This flow demands the users to enter their credentials
into the client. The client in turn can exchange them for an access token.
Although this undermines the ideas of OAuth 2 in some way, it is a popular
approach for business applications where users don't have a problem with
entrusting the client with their passwords.
To simplify the configuration of the
library it can now read the discovery document that is described by OIDC.
The new version can also use refresh
tokens to fetch a new access token, for instance after it expired. Using this
approach sliding expiration can be implemented. It is important to note that
the implicit flow doesn't allow for refresh tokens by design. Therefore, the
lib only supports refresh tokens when using the password flow.
Querying the userinfo endpoint
OIDC also defines a userinfo endpoint
that returns some information about the current user. As the password flow does
not support issuing an identity token, this endpoint can be used instead.