-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GIS web demo, refactor the other web samples a bit
- Loading branch information
Showing
6 changed files
with
93 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 contains 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'dart:html' show ButtonElement, querySelector; | ||
|
||
import 'package:googleapis_auth/auth_browser.dart'; | ||
|
||
import 'web_shared.dart'; | ||
|
||
String? _accessToken; | ||
|
||
final _revokeButton = querySelector('#revoke') as ButtonElement; | ||
|
||
void main() { | ||
final loginButton = querySelector('#login') as ButtonElement; | ||
loginButton.onClick.listen((event) => _login()); | ||
|
||
final loginCodeButton = querySelector('#loginCode') as ButtonElement; | ||
loginCodeButton.onClick.listen((event) => _loginCode()); | ||
|
||
_revokeButton.onClick.listen((event) async { | ||
if (_accessToken == null) return; | ||
|
||
await revokeConsent(_accessToken!); | ||
|
||
_accessToken = null; | ||
}); | ||
} | ||
|
||
Future<void> _login() async { | ||
final response = await requestAccessCredentials( | ||
clientId: clientId().identifier, | ||
scopes: ['openid', 'email'], | ||
prompt: 'consent', | ||
// ignore: deprecated_member_use | ||
logLevel: 'debug', | ||
); | ||
|
||
logToTextArea([ | ||
response.accessToken.toJson(), | ||
response.scopes, | ||
].join('\n')); | ||
|
||
_accessToken = response.accessToken.data; | ||
|
||
_revokeButton.disabled = false; | ||
} | ||
|
||
Future<void> _loginCode() async { | ||
final response = await requestAuthorizationCode( | ||
clientId: clientId().identifier, | ||
scopes: ['openid', 'email'], | ||
// ignore: deprecated_member_use | ||
logLevel: 'debug', | ||
); | ||
|
||
logToTextArea([ | ||
response.code, | ||
response.scopes, | ||
].join('\n')); | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="google_identity_demo.dart.js" defer async ></script> | ||
</head> | ||
<body> | ||
|
||
<p> | ||
<button id="login">login</button></p> | ||
<button id="loginCode">login with code</button></p> | ||
|
||
<button id="revoke" disabled>revoke</button></p> | ||
|
||
<textarea cols="80" rows="30"> </textarea> | ||
|
||
</body> | ||
</html> |
This file contains 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 contains 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 contains 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