Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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);
```