Authorization in Angular UI
OAuth is preconfigured in Angular application templates. So, when you start a project using the CLI (or Suite, for that matter), authorization already works. ABP Angular UI packages are using angular-oauth2-oidc library for managing OAuth in the Angular client. You can find OAuth configuration in the environment.ts files.
Authorization Code Flow
This configuration results in an OAuth authorization code flow with PKCE. According to this flow, the user is redirected to an external login page which is built with MVC. So, if you need to customize the login page, please follow this community article.
Resource Owner Password Flow
If you have used the Angular UI account module in your project, you can switch to the resource owner password flow by changing the OAuth configuration in the environment.ts files as shown below:
According to this flow, the user is redirected to the login page in the account module.
Error Filtering
In AuthFlowStrategy class, there is a method called listenToOauthErrors
that listens to OAuthErrorEvent
errors. This method clears the localStorage for OAuth keys. However, in certain cases, we might want to skip this process. To achieve this, we can use the AuthErrorFilterService
.
The AuthErrorFilterService
is an abstract service that needs to be replaced with a custom implementation
By default, this service is replaced in the
@abp/ng.oauth
package
Usage
1.Create an auth-filter.provider
AuthErrorFilter:
is a model for filter object and it have 3 propertiesid:
a unique key in the list for the filter objectexecutable:
a status for the filter object. If it's false then it won't work, yet it'll stay in the listexecute:
a function that stores the skip logic
2.Add to the FeatureConfigModule
Now it'll skip the clearing of OAuth storage keys for LinkedUser
grant_type if any OAuthErrorEvent
occurs
Replace with custom implementation
Use the AbstractAuthErrorFilter<T,E>
class for signs of process.
Example
my-auth-error-filter.service.ts