longvan_dart_sdk 1.0.0-dev.1 copy "longvan_dart_sdk: ^1.0.0-dev.1" to clipboard
longvan_dart_sdk: ^1.0.0-dev.1 copied to clipboard

LongVan Dart SDK - A comprehensive SDK for LongVan platform with OAuth 2.0/OIDC authentication support

LongVan Dart SDK #

A comprehensive Dart SDK for LongVan services with native GraphQL and REST support.

Features #

  • Authentication & Authorization

    • Login/logout functionality
    • JWT token management
    • User registration and profile management
    • OTP (One-Time Password) support
    • OAuth 2.0 / OIDC Authentication with PKCE support
  • Multi-environment Support

    • Development, staging, and production environments
    • Configurable endpoints and settings
  • GraphQL Integration

    • Built-in GraphQL client
    • Query and mutation support
    • Subscription handling
  • Security

    • Secure token storage
    • Request signing and validation
    • Environment-specific configurations
    • Professional OAuth security with PKCE and JWT decoding
  • Multi-tenant Ready: Flexible context management for any application type

  • Type Safe: Full Dart type safety and compile-time checks

  • Service-Specific Endpoints: Each service has its own dedicated endpoint

  • Extensible: Easy to add new services and customize functionality

Quick Start #

{{ ... }}

import 'package:longvan_dart_sdk/longvan_dart_sdk.dart';

void main() async {
  // Tạo SDK instance với environment và context
  final sdk = await LongVanSDK.create(
    environment: Environment.dev,
    orgId: 'your-org-id',
    storeId: 'your-store-id',
  );

  // Sử dụng authentication service
  final loginResponse = await sdk.auth.login(LoginRequest(
    username: 'user@example.com',
    password: 'password123',
  ));

  // Cập nhật context với thông tin login
  sdk.setContext(
    orgId: loginResponse.orgId,
    accessToken: loginResponse.accessToken,
  );

  print('Đăng nhập thành công: ${loginResponse.fullName}');
}
// Xác thực OTP
final validateResponse = await sdk.auth.validateOTP('123456', '+84123456789');

// Lấy access token bằng OTP
final tokenResponse = await sdk.auth.getAccessTokenByOTP('123456', '+84123456789');

🌍 Environment Configuration #

SDK hỗ trợ hai môi trường với endpoint riêng cho từng service:

Development (dev) #

  • Auth: https://crm.dev.longvan.vn/authorization-gateway/graphql
  • Product: https://product-service.dev.longvan.vn/product-service/graphql
  • User: https://user.dev.longvan.vn/user-gateway/graphql
  • Order: https://storefront.dev.longvan.vn/v2

Production (live) #

  • Auth: https://crm.longvan.vn/authorization-gateway/graphql
  • Product: https://product-service.longvan.vn/product-service/graphql
  • User: https://user.longvan.vn/user-gateway/graphql
  • Order: https://storefront.longvan.vn/v2

🎛️ Context Management #

// Cập nhật context
sdk.setContext(
  orgId: 'new-org-id',
  storeId: 'new-store-id',
  accessToken: 'new-access-token',
);

// Kiểm tra trạng thái xác thực
if (sdk.isAuthenticated) {
  print('Người dùng đã được xác thực');
}

⚠️ Error Handling #

SDK trả về lỗi trực tiếp từ BE, không wrap hay xử lý gì thêm:

try {
  final loginResponse = await sdk.auth.login(loginRequest);
  print('Đăng nhập thành công: ${loginResponse.fullName}');
} on GraphQLException catch (e) {
  // Lỗi GraphQL trực tiếp từ BE
  print('GraphQL Error: ${e.message}');
  if (e.errors != null) {
    for (final error in e.errors!) {
      print('- ${error['message']}');
    }
  }
} on RestException catch (e) {
  // Lỗi REST trực tiếp từ BE  
  print('REST Error: ${e.message} (Status: ${e.statusCode})');
} catch (e) {
  // Các lỗi khác (network, parsing, etc.)
  print('Lỗi: $e');
}

📝 Example #

Xem file example/auth_example.dart để biết cách sử dụng chi tiết.

🤝 Contributing #

  1. Fork repository
  2. Tạo feature branch
  3. Commit changes
  4. Push to branch
  5. Mở Pull Request

📄 License #

MIT License

0
likes
0
points
74
downloads

Documentation

Documentation

Publisher

unverified uploader

Weekly Downloads

LongVan Dart SDK - A comprehensive SDK for LongVan platform with OAuth 2.0/OIDC authentication support

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

graphql, http, json_annotation, logging, meta, oauth2

More

Packages that depend on longvan_dart_sdk