This package provides an implementation of application default credentials for Dart.
The Application Default Credentials provide a simple way to get authorization credentials for use in calling Google APIs.
They are best suited for cases when the call needs to have the same identity and authorization level for the application independent of the user. This is the recommended approach to authorize calls to Cloud APIs, particularly when you're building an application that uses Google Compute Engine.
import 'package:http/http.dart';
import 'package:googleapis_auth_default_credentials/googleapis_auth_default_credentials.dart';
import 'package:googleapis_auth/auth_io.dart';
import 'package:googleapis/storage/v1.dart';
const _SCOPES = const [StorageApi.DevstorageReadOnlyScope];
main() async {
Client client = new Client();
AccessCredentials credentials = await obtainDefaultAccessCredentials(_SCOPES, client);
AuthClient authClient = authenticatedClient(client, credentials);
final storage = new StorageApi(authClient);
final buckets = await storage.buckets.list('test');
print(buckets.toJson());
client.close();
}
Add this to your package's pubspec.yaml file:
dependencies:
googleapis_auth_default_credentials: "^0.1.0"
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:googleapis_auth_default_credentials/googleapis_auth_default_credentials.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.1.0 | Oct 6, 2016 |
|
|
We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
0 | / 100 |
Health:
Code health derived from static analysis.
[more]
|
97 | / 100 |
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
45 | / 100 |
Overall score:
Weighted score of the above.
[more]
|
38 |
Detected platforms: Flutter, other
Primary library:
package:googleapis_auth_default_credentials/googleapis_auth_default_credentials.dart
with components:io
.
Fix .analysis_options
.
We were unable to parse
.analysis_options
.
Package is pre-v1 release.
While there is nothing inherently wrong with versions of
0.*.*
, it usually means that the author is still experimenting with the general direction API.
Fix analysis and formatting issues.
Analysis or formatting checks reported 5 hints.
Strong-mode analysis of
lib/src/default_credentials.dart
gave the following hint:line: 77 col: 16
'JSON' is deprecated and shouldn't be used.Strong-mode analysis of
lib/src/user_credentials.dart
gave the following hint:line: 23 col: 14
'JSON' is deprecated and shouldn't be used.
Use analysis_options.yaml
.
Rename old
.analysis_options
file toanalysis_options.yaml
.
Enable strong mode analysis.
Strong mode helps you to detect bugs and potential issues earlier.Start your
analysis_options.yaml
file with the following:analyzer: strong-mode: true
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=1.8.0 <2.0.0 | ||
googleapis | ^0.31.0 | 0.31.0 | 0.50.1 |
googleapis_auth | ^0.2.3 | 0.2.5 | |
http | >=0.11.1 <0.12.0 | 0.11.3+16 | |
path | ^1.3.9 | 1.5.1 | |
Transitive dependencies | |||
_discoveryapis_commons | 0.1.6 | ||
async | 2.0.6 | ||
charcode | 1.1.1 | ||
collection | 1.14.9 | ||
convert | 2.0.1 | ||
crypto | 2.0.2+1 | ||
http_parser | 3.1.1 | ||
source_span | 1.4.0 | ||
string_scanner | 1.0.2 | ||
typed_data | 1.1.5 | ||
Dev dependencies | |||
test | >=0.12.0 <0.13.0 |