https://github.com/otajonogli/drf_client
A complete implementation of Authentication and Rest API connection with the backends that use Django Rest Framework. Supports refreshing and storing tokens securely.
https://github.com/otajonogli/drf_client
django django-flutter django-oauth-toolkit django-rest-framework drf-client flutter token-authetication
Last synced: 4 months ago
JSON representation
A complete implementation of Authentication and Rest API connection with the backends that use Django Rest Framework. Supports refreshing and storing tokens securely.
- Host: GitHub
- URL: https://github.com/otajonogli/drf_client
- Owner: otajonogli
- License: mit
- Created: 2024-05-27T13:26:26.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-03T11:09:04.000Z (about 2 years ago)
- Last Synced: 2026-01-11T16:20:58.232Z (5 months ago)
- Topics: django, django-flutter, django-oauth-toolkit, django-rest-framework, drf-client, flutter, token-authetication
- Language: Dart
- Homepage: https://pub.dev/packages/drf_client
- Size: 295 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Helps you to automatically authenticate and store tokens and refresh them, also make api requests using them.
This project is under development. View the GitHub code and contribute 👉 https://github.com/Otajonov/drf_client
## Features
- ✅ Automatically store tokens using Flutter Secure Storage
- ✅ Automatically refresh tokens
- ✅ Supports Oauth2 by Django Oauth Toolkit
- ✅ Easy REST API call with auth credentials
- ✅ More coming soon ...
## Getting started
To start using package, add it to your dependencies by running this:
```shell
flutter pub add drf_client
```
or add this line into your pubspec.yaml under dependencies:
```yaml
dependencies:
flutter:
sdk: flutter
# your other dependencies ...
drf_client:
```
Then import the package in desired files:
```dart
import 'package:drf_client/drf_client.dart';
```
Enjoy coding!
## Usage
Firstly, initialize the config:
```dart
void main() {
// existing code
DrfClient client = DrfClient();
client.addConfig('your-app', DrfConfig(
authType: AuthType.drfBuiltInAuth,
baseUrl: 'https://your-app.com/api',
tokenUrl: 'https://your-app.com/api/token',
refreshTokenUrl: 'https://your-app.com/api/token/refresh',
usernameField: 'username', // default username, change this if you are using custom user model in django
passwordField: 'password', // def password, change this if you changed password field in you user model
refreshField: 'refresh_token', // change this to comply with your token refresh logic if JWT used
// Set this if u are using Authorization Code over Django-oauth-toolkit
// oauthConfig: OauthConfig(
// clientId: "",
// clientSecret: "",
// authorizationEndpointUrl: "https://ilmchat.com/auth/authorize/",
// redirectScheme: 'you-app-shceme'
//
// )
));
}
```
You can also set multiple config so that you can make request and authenticate multiple django servers at the same code by giving specific app name in config.
## Authenticating users
via drfBuiltInAuth:
```dart
DrfClient client = DrfClient();
client.loginDrfBuiltIn()
```
## making requests
```dart
DrfClient client = DrfClient();
client.get() // post() put() patch() delete()
```
It will use stored user token in requests if logged in.
You can remove Token from auth header by includeToken: false