|
| 1 | +# JFramework Dart Library |
| 2 | + |
| 3 | +[](https://pub.dev/packages/user_auth_sdk) |
| 4 | +[](https://opensource.org/licenses/MIT) |
| 5 | +[](https://github.com/yourusername/user_auth_sdk/actions) |
| 6 | + |
| 7 | +A Dart SDK for seamless integration with JFramework APIs, supporting both API Key and Auth Key authentication flows. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **Dual Authentication Methods**: |
| 12 | + - `APIKey` header for service-to-service auth |
| 13 | + - `AuthKey` header for user credential flows |
| 14 | +- **Complete User Management**: |
| 15 | + - CRUD operations for users |
| 16 | + - Session management |
| 17 | + - Role-based permissions |
| 18 | +- **Token Management**: |
| 19 | + - Automatic token storage |
| 20 | + - Secure credential handling |
| 21 | + - Token refresh flow |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +Add to your `pubspec.yaml`: |
| 26 | + |
| 27 | +```yaml |
| 28 | +dependencies: |
| 29 | + jfw_dart: ^1.0.0 |
| 30 | +``` |
| 31 | +
|
| 32 | +## Usage |
| 33 | +
|
| 34 | +### 1. Auth Key Authentication |
| 35 | +``` dart |
| 36 | +final authProvider = AuthKeyProvider(null); |
| 37 | + |
| 38 | + final client = JfwClient( |
| 39 | + brandUrl: 'YOUR_BRAND_URL', |
| 40 | + authProvider: authProvider, |
| 41 | + ); |
| 42 | +``` |
| 43 | + |
| 44 | +### 2. Username/Password Authentication |
| 45 | +``` dart |
| 46 | +
|
| 47 | +final authService = AuthService(client); |
| 48 | +
|
| 49 | +AuthenticateRequest request = AuthenticateRequest( |
| 50 | + username: 'user_username', // Replace with user's username |
| 51 | + password: 'user_password', // Replace with user's password |
| 52 | +); |
| 53 | +
|
| 54 | +// Login with credentials |
| 55 | +final authResponse = await authService.loginWithCredentials(request); |
| 56 | +
|
| 57 | +// If the login is successful, the response will contain the auth key |
| 58 | +client.updateAuthProvider(AuthKeyProvider(response.authKey)); |
| 59 | +
|
| 60 | +print('Login successful! Auth Key: ${response.authKey}'); |
| 61 | +
|
| 62 | +
|
| 63 | +``` |
| 64 | + |
| 65 | +### 3. Making Authenticated Requests |
| 66 | +``` dart |
| 67 | +// Subsequent requests will automatically include the Auth-Key header |
| 68 | +final userService = UserService(client); |
| 69 | +final user = await userService.getCurrentUser(); |
| 70 | +
|
| 71 | +print('Current user: id=${user.id}, email=${user.emailAddress}, username=${user.username}'); |
| 72 | +``` |
| 73 | + |
| 74 | +## Contributing |
| 75 | +1. Fork the repository |
| 76 | +2. Create a feature branch (git checkout -b feature/AmazingFeature) |
| 77 | +3. Commit your changes (git commit -m 'Add amazing feature') |
| 78 | +4. Push to the branch (git push origin feature/AmazingFeature) |
| 79 | +5. Open a Pull Request |
0 commit comments