-
Notifications
You must be signed in to change notification settings - Fork 0
Build/update deps #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
168c993
chore: remove code coverage data
fulleni fa855c0
chore: update .gitignore file
fulleni 2aa303a
build: update very_good_analysis to version 9.0.0
fulleni dc564f6
build(deps): update dependencies
fulleni 38bcff1
docs(README): revamp with feature showcase, licensing info, and badges
fulleni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
# See https://www.dartlang.org/guides/libraries/private-files | ||
|
||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
build/ | ||
pubspec.lock | ||
coverage/ |
This file contains hidden or 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 |
---|---|---|
@@ -1,108 +1,46 @@ | ||
# auth_api | ||
<div align="center"> | ||
<img src="https://avatars.githubusercontent.com/u/202675624?s=400&u=dc72a2b53e8158956a3b672f8e52e39394b6b610&v=4" alt="Flutter News App Toolkit Logo" width="220"> | ||
<h1>Auth API</h1> | ||
<p><strong>A concrete API implementation of the `AuthClient` interface for the Flutter News App Toolkit.</strong></p> | ||
</div> | ||
|
||
 | ||
[](https://pub.dev/packages/very_good_analysis) | ||
[](https://polyformproject.org/licenses/free-trial/1.0.0) | ||
<p align="center"> | ||
<img src="https://img.shields.io/badge/coverage-_%25-red?style=for-the-badge" alt="coverage"> | ||
<a href="https://flutter-news-app-full-source-code.github.io/docs/"><img src="https://img.shields.io/badge/LIVE_DOCS-VIEW-slategray?style=for-the-badge" alt="Live Docs: View"></a> | ||
<a href="https://github.com/flutter-news-app-full-source-code"><img src="https://img.shields.io/badge/MAIN_PROJECT-BROWSE-purple?style=for-the-badge" alt="Main Project: Browse"></a> | ||
</p> | ||
|
||
Concrete API implementation of the `AuthClient` interface defined in | ||
`package:auth_client`. This package provides the logic for interacting | ||
with a backend authentication service via HTTP requests using | ||
`package:http_client`. | ||
This `auth_api` package provides a concrete API implementation of the `AuthClient` interface (defined in `package:auth_client`) within the [**Flutter News App Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code). It encapsulates the logic for interacting with a backend authentication service via HTTP requests, leveraging `package:http_client` for underlying communication and standardized error handling. This package is crucial for applications that need to connect to a remote authentication service, ensuring consistent and robust authentication mechanisms across the Flutter mobile app, web dashboard, and Dart Frog backend API. | ||
|
||
## Getting Started | ||
## ⭐ Feature Showcase: Robust Backend Authentication Integration | ||
|
||
Add this package to your `pubspec.yaml` dependencies: | ||
This package offers a comprehensive set of features for integrating with a backend authentication service. | ||
|
||
```yaml | ||
dependencies: | ||
auth_api: | ||
git: | ||
url: https://github.com/flutter-news-app-full-source-code/auth-api.git | ||
# Optionally specify a ref (branch, tag, commit hash) | ||
# ref: main | ||
``` | ||
<details> | ||
<summary><strong>🧱 Core Functionality</strong></summary> | ||
|
||
You also need to include `http_client` and `auth_client` (which this | ||
package depends on). | ||
### 🚀 `AuthClient` Implementation | ||
- **`AuthApi` Class:** A concrete implementation of the `AuthClient` interface, providing a standardized way to interact with a remote authentication service. | ||
- **HTTP-Based Communication:** Utilizes `package:http_client` for making HTTP requests to the backend authentication service. | ||
|
||
## Features | ||
### 🔐 Authentication Flows | ||
- **`requestSignInCode`:** Initiates the process of requesting a sign-in code via email. | ||
- **`verifySignInCode`:** Verifies the sign-in code to complete the authentication process. | ||
- **`signInAnonymously`:** Allows users to sign in anonymously, creating a temporary user identity on the backend. | ||
- **`getCurrentUser`:** Retrieves the currently authenticated user's details from the backend. | ||
- **`authStateChanges` Stream:** Provides a stream for monitoring real-time authentication state changes. | ||
- **`signOut`:** Handles signing out the current user from the backend. | ||
|
||
Provides an `AuthApi` class implementing `AuthClient` with the following | ||
capabilities: | ||
### 🛡️ Standardized Error Handling | ||
- **`HttpException` Propagation:** Propagates standardized `HttpException` errors (from `core`) from the underlying `http_client`, ensuring consistent and predictable error management across the application layers. | ||
|
||
* Requesting a sign-in code via email (`requestSignInCode`). | ||
* Verifying the sign-in code to complete authentication (`verifySignInCode`). | ||
* Signing in anonymously (`signInAnonymously`). | ||
* Retrieving the current authenticated user (`getCurrentUser`). | ||
* Monitoring authentication state changes via a stream (`authStateChanges`). | ||
* Signing out the current user (`signOut`). | ||
|
||
## Usage | ||
|
||
Instantiate `AuthApi` with a configured `HttpClient` instance: | ||
|
||
```dart | ||
import 'package:auth_api/auth_api.dart'; | ||
import 'package:auth_client/auth_client.dart'; | ||
import 'package:http_client/http_client.dart'; | ||
void main() async { | ||
// Configure HttpClient (replace with your actual base URL and token logic) | ||
final httpClient = HttpClient( | ||
baseUrl: 'https://your-api.com', | ||
tokenProvider: () async => 'YOUR_AUTH_TOKEN', // Or null if not logged in | ||
); | ||
// Create the auth API client | ||
final AuthClient authClient = AuthApi(httpClient: httpClient); | ||
// Listen to authentication state changes | ||
authClient.authStateChanges.listen((user) { | ||
if (user != null) { | ||
// To check for an anonymous user, you would typically check their role, | ||
// e.g., if (user.role == UserRole.guestUser) { ... } | ||
// Assuming UserRole enum is accessible/imported. | ||
print('User signed in: ${user.id}, Role: ${user.role}'); | ||
} else { | ||
print('User signed out.'); | ||
} | ||
}); | ||
try { | ||
// Example: Request sign-in code | ||
await authClient.requestSignInCode('user@example.com'); | ||
print('Sign-in code requested.'); | ||
// Example: Verify code (replace '123456' with actual code) | ||
// final authResponse = await authClient.verifySignInCode('user@example.com', '123456'); | ||
// print('User verified: ${authResponse.user.id}, Token: ${authResponse.token}'); | ||
// Example: Sign in anonymously | ||
// final anonAuthResponse = await authClient.signInAnonymously(); | ||
// print('Signed in anonymously: ${anonAuthResponse.user.id}, Token: ${anonAuthResponse.token}'); | ||
// Example: Get current user | ||
// final currentUser = await authClient.getCurrentUser(); | ||
// if (currentUser != null) { ... } | ||
// Example: Sign out | ||
// await authClient.signOut(); | ||
} on HttpException catch (e) { | ||
print('Authentication error: $e'); | ||
} finally { | ||
// Remember to dispose the client if it has resources like streams | ||
// (In this specific implementation, AuthApi has a dispose method) | ||
(authClient as AuthApi).dispose(); | ||
} | ||
} | ||
``` | ||
### 💉 Dependency Injection Ready | ||
- **`HttpClient` Dependency:** Requires a configured `HttpClient` instance (from `package:http_client`) via its constructor, promoting loose coupling and testability. | ||
|
||
> **💡 Your Advantage:** This package provides a robust and production-ready API client for backend authentication. It simplifies the integration of remote authentication services, leverages standardized error handling, and ensures consistent authentication flows across your application ecosystem. | ||
</details> | ||
fulleni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## 🔑 Licensing | ||
|
||
This package is source-available and licensed under the [PolyForm Free Trial 1.0.0](LICENSE). Please review the terms before use. | ||
|
||
For commercial licensing options that grant the right to build and distribute unlimited applications, please visit the main [**Flutter News App - Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code) organization. | ||
This `auth_api` package is an integral part of the [**Flutter News App Full Source Code Toolkit**](https://github.com/flutter-news-app-full-source-code). For comprehensive details regarding licensing, including trial and commercial options for the entire toolkit, please refer to the main toolkit organization page. |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.