Skip to content

Commit 1a1692b

Browse files
committed
Initial commit
0 parents  commit 1a1692b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2803
-0
lines changed

.dart_tool/package_config.json

Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.

.github/workflows/dart.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Dart CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: dart-lang/setup-dart@v1
11+
- run: dart pub get
12+
- run: dart analyze
13+
- run: dart test
14+
- run: dart format --output none --set-exit-if-changed .

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "jfw-dart",
9+
"request": "launch",
10+
"type": "dart"
11+
}
12+
]
13+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 [1bytesoftware]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# JFramework Dart Library
2+
3+
[![Pub Version](https://img.shields.io/pub/v/user_auth_sdk)](https://pub.dev/packages/user_auth_sdk)
4+
[![License: MIT](https://img.shields.io/badge/license-MIT-purple.svg)](https://opensource.org/licenses/MIT)
5+
[![CI Status](https://github.com/yourusername/user_auth_sdk/actions/workflows/dart.yml/badge.svg)](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

example.jpg

1.27 MB
Loading

example/auth_main.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'package:jfw_dart/jfw.dart';
2+
import 'package:jfw_dart/src/auth/auth_key_auth.dart';
3+
4+
void main() async {
5+
6+
final brandUrl = "YOUR_BRAND_URL";
7+
8+
// Option 1: Auth Key Authentication
9+
final authProvider = AuthKeyProvider(null);
10+
11+
// Option 2: API Key Authentication
12+
// final authProvider = ApiKeyProvider('your-api-key-here');
13+
14+
final client = JfwClient(
15+
brandUrl: brandUrl,
16+
authProvider: authProvider,
17+
);
18+
19+
final authService = AuthService(client);
20+
21+
try {
22+
// Instantiate the request with the required parameters
23+
AuthenticateRequest request = AuthenticateRequest(
24+
username: 'username', // Replace with your username
25+
password: 'password', // Replace with your password
26+
);
27+
28+
// Login with credentials
29+
final response = await authService.loginWithCredentials(request);
30+
31+
// If the login is successful, the response will contain the auth key
32+
client.updateAuthProvider(AuthKeyProvider(response.authKey));
33+
34+
print('Login successful! Auth Key: ${response.authKey}');
35+
36+
// Subsequent requests will automatically include the Auth-Key header
37+
final userService = UserService(client);
38+
final user = await userService.getCurrentUser();
39+
print('Current user: id=${user.id}, email=${user.emailAddress}, username=${user.username}');
40+
} catch (e) {
41+
print('Error: $e');
42+
}
43+
}

example/cdn_main.dart

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import 'dart:io';
2+
3+
import 'package:jfw_dart/jfw.dart';
4+
import 'package:jfw_dart/src/auth/auth_key_auth.dart';
5+
6+
void main() async {
7+
// Option 1: Auth Key Authentication.
8+
final authKey = "YOUR_AUTH_KEY"; // This value is will be generated before call authService.loginWithCredentials()
9+
final brandUrl = "YOUR_BRAND_URL";
10+
11+
final authProvider = AuthKeyProvider(authKey);
12+
13+
final client = JfwClient(
14+
brandUrl: brandUrl,
15+
authProvider: authProvider,
16+
);
17+
18+
final cdnService = CdnService(client);
19+
20+
try {
21+
22+
final file = new File('example.jpg');
23+
24+
final request = UploadCdnRequest(
25+
uploadFile: file,
26+
prefixFolder: 'tests',
27+
refObject: 'example',
28+
refId: 1000
29+
30+
);
31+
32+
if(!await file.exists()){
33+
throw Exception('File not found');
34+
}
35+
36+
// Call the API to get the current user
37+
final response = await cdnService.uploadFile(request);
38+
39+
print('Result fileId: ${response.fileId}');
40+
print('Result url: ${response.url}');
41+
42+
} catch (e) {
43+
print('Error: ${e}');
44+
}
45+
}

example/device_main.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:jfw_dart/jfw.dart';
2+
import 'package:jfw_dart/src/auth/auth_key_auth.dart';
3+
4+
void main() async {
5+
// Auth Key Authentication.
6+
final authKey = "H+a+SZuunxY2qcvmC1B3yj3BuenCit1IeVRaazFsRGNXR21UZjA2c3JiTElaZz09cVIyeElZRmdMODZoV1RoVmFlMHJwZzc0NmordE5EZmxXRS9BU0JzdWtLaz0="; // This value is will be generated before call authService.loginWithCredentials()
7+
final brandUrl = "my.boostpte.com";
8+
9+
final authProvider = AuthKeyProvider(authKey);
10+
11+
final client = JfwClient(
12+
brandUrl: brandUrl,
13+
authProvider: authProvider,
14+
);
15+
16+
final deviceService = DeviceService(client);
17+
18+
try {
19+
20+
final query = DeviceQueryRequest(
21+
pageNumber: 0,
22+
pageSize: 10,
23+
);
24+
25+
// Call the API to get the current user
26+
final response = await deviceService.getDevices(query: query);
27+
28+
print('Result total items: ${response.totalItems}');
29+
30+
for (var item in response.items) {
31+
print('name=${item.name}, os=${item.osDevice}, status=${item.status}');
32+
}
33+
34+
} catch (e) {
35+
print('Error: ${e}');
36+
}
37+
}

example/user_main.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:jfw_dart/jfw.dart';
2+
import 'package:jfw_dart/src/auth/auth_key_auth.dart';
3+
4+
void main() async {
5+
// Option 1: Auth Key Authentication.
6+
final authKey = "YOUR_AUTH_KEY";
7+
final brandUrl = "YOUR_BRAND_URL";
8+
9+
final authProvider = AuthKeyProvider(authKey);
10+
11+
// Option 2: API Key Authentication
12+
// final authProvider = ApiKeyProvider('your-api-key-here');
13+
14+
15+
final client = JfwClient(
16+
brandUrl: brandUrl,
17+
authProvider: authProvider,
18+
);
19+
20+
final userService = UserService(client);
21+
22+
try {
23+
// Call the API to get the current user
24+
final response = await userService.getCurrentUser();
25+
26+
print('Result getCurrentUser: ${response.id}');
27+
} catch (e) {
28+
print('Error: $e');
29+
}
30+
}

0 commit comments

Comments
 (0)