Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lamnhan066/safe_browsing
Using google safe browsing API to detect whether the URL is safe.
https://github.com/lamnhan066/safe_browsing
Last synced: 7 days ago
JSON representation
Using google safe browsing API to detect whether the URL is safe.
- Host: GitHub
- URL: https://github.com/lamnhan066/safe_browsing
- Owner: lamnhan066
- License: mit
- Created: 2023-07-25T05:14:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-08T10:06:15.000Z (about 1 year ago)
- Last Synced: 2023-10-09T10:19:25.262Z (about 1 year ago)
- Language: Dart
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Safe Browsing
Using google safe browsing API to detect whether the URL is safe.
## Required
Make sure that you're enabled the SafeBrowsing API in your google cloud console:
- **STEP 1:** Go to
- **STEP 2:** Choose your current project
- **STEP 3:** Press `Enable`## Usage
This plugin requires you to use `flutterfire_cli` to create the `DefaultFirebaseOptions` for your project. [Read more](https://firebase.flutter.dev/).
### Create the instance
``` dart
/// Create the instance from the `DefaultFirebaseOptions`
/// This class is created by `flutterfire_cli`
final safeBrowsing = SafeBrowsing(
options: DefaultFirebaseOptions.currentPlatform,
isDebug: !kReleaseMode,
);/// The URL you want to check
final url = 'https://example.com';/// Check whether the URL is safe and return `SafeBrowsingState`
final state = await safeBrowsing.checkUrl(url);/// Check whether the URL is safe and return `bool`
final isSafe = await safeBrowsing.isUrlSafe(url);
```### Result state of the checking
``` dart
state.isSafe // Means the result is safe
state.isNotSafe // Means the result is not safe. Different with `!state.isSafe`
state.isError // Means there is issue with the request
```Please notice that the `!state.isSafe` is different from `state.isNotSafe` because the `state.isError` maybe occured.
### More specific result by using `state.type`
``` dart
/// Safe
SafeBrowsingStateType.safe/// Not safe. See `state.matches` for the details.
SafeBrowsingStateType.notSafe/// Empty input
SafeBrowsingStateType.empty/// Error with the request
SafeBrowsingStateType.requestError/// Unknow error
SafeBrowsingStateType.unknown
```### Get the list of `TheatMatch`s when the `state.isNotSafe`
``` dart
final listThreatMatches = state.matches;
```## Advanced
``` dart
/// Check the entries
final state = safeBrowsing.check{
[ThreatEntry(url: 'url')],threatTypes: [
ThreatType.MALWARE,
ThreatType.SOCIAL_ENGINEERING,
ThreatType.UNWANTED_SOFTWARE,
ThreatType.POTENTIALLY_HARMFUL_APPLICATION,
],platformTypes: [
PlatformType.ALL_PLATFORMS,
],threatEntryTypes: [
ThreatEntryType.URL,
],
}
```## Additional
Use this method to validate the URL
``` dart
SafeBrowsing.validateUrl(url);
```