Skip to content

Commit

Permalink
custom headers with API Key authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
faithoflifedev committed Jul 19, 2024
1 parent 4bab47d commit 413e61c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/google_vision/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.1+2

* custom headers with API Key authentication Issue #23

## 1.2.1+1

* updated documentation
Expand Down
2 changes: 1 addition & 1 deletion packages/google_vision/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To use this package, add the dependency to your `pubspec.yaml` file:
```yaml
dependencies:
...
google_vision: ^1.2.1+1
google_vision: ^1.2.1+2
```
### Obtaining Authorization Credentials
Expand Down
4 changes: 3 additions & 1 deletion packages/google_vision/example/face_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ void main() async {
// await GoogleVision.withJwtFile('example/service_credentials.json');

final googleVision = await GoogleVision.withApiKey(
Platform.environment['GOOGLE_VISION_API_KEY'] ?? '[YOUR API KEY]');
Platform.environment['GOOGLE_VISION_API_KEY'] ?? '[YOUR API KEY]',
additionalHeaders: {'com.xxx.xxx': 'X-Ios-Bundle-Identifier'},
);

print('checking...');

Expand Down
2 changes: 1 addition & 1 deletion packages/google_vision/lib/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ library meta;
import 'dart:convert' show json;

final pubSpec = json.decode(
'{"name":"google_vision","version":"1.2.1+1","homepage":"https://github.com/faithoflifedev/google_vision/tree/main/packages/google_vision","environment":{"sdk":">=3.2.0 <4.0.0"},"description":"Allows you to add Google Visions image labeling, face, logo, and landmark detection, OCR, and detection of explicit content, into cross platform applications.","dependencies":{"args":"^2.5.0","collection":"^1.18.0","crypto_keys_plus":"^0.4.0","dio":"^5.4.3+1","http":"^1.2.1","image":"^4.1.7","jose_plus":"^0.4.6","json_annotation":"^4.9.0","retrofit":"^4.1.0","universal_io":"^2.2.2"},"dev_dependencies":{"build_runner":"^2.4.9","grinder":"^0.9.5","json_serializable":"^6.8.0","lints":"^4.0.0","publish_tools":"^1.0.0+4","retrofit_generator":"^8.1.0","test":"^1.25.5"},"executables":{"vision":""},"repository":"https://github.com/faithoflifedev/google_vision"}');
'{"name":"google_vision","version":"1.2.1+2","homepage":"https://github.com/faithoflifedev/google_vision/tree/main/packages/google_vision","environment":{"sdk":">=3.2.0 <4.0.0"},"description":"Allows you to add Google Visions image labeling, face, logo, and landmark detection, OCR, and detection of explicit content, into cross platform applications.","dependencies":{"args":"^2.5.0","collection":"^1.18.0","crypto_keys_plus":"^0.4.0","dio":"^5.4.3+1","http":"^1.2.1","image":"^4.1.7","jose_plus":"^0.4.6","json_annotation":"^4.9.0","retrofit":"^4.1.0","universal_io":"^2.2.2"},"dev_dependencies":{"build_runner":"^2.4.9","grinder":"^0.9.5","json_serializable":"^6.8.0","lints":"^4.0.0","publish_tools":"^1.0.0+4","retrofit_generator":"^8.1.0","test":"^1.25.5"},"executables":{"vision":""},"repository":"https://github.com/faithoflifedev/google_vision"}');
11 changes: 9 additions & 2 deletions packages/google_vision/lib/src/google_vision_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@ class GoogleVision {
}

/// Authenticate using an API key.
static Future<GoogleVision> withApiKey(String apiKey) async {
static Future<GoogleVision> withApiKey(
String apiKey, {
Map<String, String>? additionalHeaders,
}) async {
_apiKey = apiKey;

if (additionalHeaders != null) {
dio.options.headers.addAll(additionalHeaders);
}

return GoogleVision();
}

Expand Down Expand Up @@ -145,7 +152,7 @@ class GoogleVision {

/// Face Detection detects multiple faces within an image along with the
/// associated key facial attributes such as emotional state or wearing
/// headwear.
/// head-wear.
Future<List<FaceAnnotation>> faceDetection(
JsonImage jsonImage, {
int maxResults = 10,
Expand Down
2 changes: 1 addition & 1 deletion packages/google_vision/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: google_vision
description: Allows you to add Google Visions image labeling, face, logo, and landmark detection, OCR, and detection of explicit content, into cross platform applications.
version: 1.2.1+1
version: 1.2.1+2
repository: https://github.com/faithoflifedev/google_vision
homepage: https://github.com/faithoflifedev/google_vision/tree/main/packages/google_vision

Expand Down

0 comments on commit 413e61c

Please sign in to comment.