-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fresh package for authentication
- Loading branch information
1 parent
1a8e773
commit f0d2757
Showing
25 changed files
with
160 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Authentication | ||
|
||
The guide describes token-based authentication which relies on **access** and **refresh** tokens. | ||
|
||
## Fresh | ||
|
||
The recommended approach is to use the `fresh` package. | ||
|
||
[**Fresh**](https://pub.dev/packages/fresh) is a token refresh library for dart. This library consists of a collection of packages which specialize in a particular aspect of token refresh. | ||
|
||
Project contains preconfigured classes for `fresh_dio` package to make its usage even more easier. | ||
|
||
Example: | ||
```dart | ||
final fresh = Fresh<AuthTokenPair>( | ||
tokenHeader: (token) => {'Authorization': 'Bearer ${token.accessToken}'}, | ||
tokenStorage: const TokenStorageImpl(FlutterSecureStorage()), | ||
refreshToken: (options, handler) async { ... }, | ||
); | ||
// Add interceptor to Dio instance. | ||
dio.interceptors.add(fresh); | ||
// Listen to authentication status changes. | ||
fresh.authenticationStatus.listen((status) { ... }); | ||
// Set token. | ||
fresh.setToken(token); | ||
// Clear token. | ||
fresh.clearToken(); | ||
``` | ||
## Token Storage | ||
|
||
`TokenStorageImpl` is an implementation of `TokenStorage<AuthTokenPair>` from `fresh` package which relies on `flutter_secure_storage`. | ||
|
||
## Auth Tokens | ||
|
||
`AuthTokenPair` is a class that represents a pair of access and refresh tokens. It is used by `TokenStorageImpl`. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
lib/common/service/token_operations/i_token_operations_service.dart
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
10 changes: 0 additions & 10 deletions
10
lib/features/shared/domain/repositories/auth_repository.dart
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.