This repository was archived by the owner on Feb 22, 2023. It is now read-only.
forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 6
[WIP] Google sign in web #85
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10e5030
gapi JS interop
ditman b721c7a
Implement some of the methods of the plugin.
ditman 1026a3a
Add stub implementations for missing methods.
ditman 4beb332
Remove field renaming from config anonymous objects as well.
ditman a53eece
Sharpen the API
ditman 209dcd7
Address PR feedback
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
gapi JS interop
- Loading branch information
commit 10e5030f87f830330c00aa838c06d6ae41f07402
There are no files selected for viewing
202 changes: 202 additions & 0 deletions
202
packages/google_sign_in/google_sign_in_web/lib/src/gapi.dart
This file contains hidden or 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,202 @@ | ||
| @JS() | ||
| /// This library implements the global gapi object | ||
| library gapi; // Poor man's package:googleapis | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:html' as html; | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
ditman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import 'package:js/js.dart'; | ||
|
|
||
| // Global window.gapi, we need to call `load('auth2', cb)` on it... | ||
| @JS('gapi') | ||
| external Gapi get gapi; | ||
|
|
||
| @JS() | ||
| abstract class Gapi { | ||
| external void load(String module, Function callback); | ||
| external Auth2 get auth2; | ||
| } | ||
|
|
||
| @JS() | ||
| abstract class Auth2 { | ||
| external GoogleAuth init(Auth2ClientConfig params); | ||
| external GoogleAuth getAuthInstance(); | ||
| // todo | ||
| external void authorize(Auth2AuthorizeConfig params, Auth2AuthorizeCallback callback); | ||
| } | ||
|
|
||
| typedef Auth2AuthorizeCallback = void Function(Auth2AuthorizeResponse response); | ||
|
|
||
|
|
||
| @JS() | ||
| abstract class Auth2CurrentUser { | ||
| external GoogleUser get(); | ||
| external void listen(Auth2CurrentUserListener listener); | ||
| } | ||
|
|
||
| typedef Auth2CurrentUserListener = void Function(bool); | ||
|
|
||
| @JS() | ||
| // https://developers.google.com/identity/sign-in/web/reference#gapiauth2initparams | ||
| abstract class GoogleAuth { | ||
| external Future<void> then(Function onInit, Function onError); | ||
| // Authentication: https://developers.google.com/identity/sign-in/web/reference#authentication | ||
| external Future<GoogleUser> signIn([Auth2SignInOptions options]); | ||
| external Future<void> signOut(); | ||
| external void disconnect(); | ||
| // Offline access not implemented | ||
| external void attachClickHandler(html.HtmlElement container, Auth2SignInOptions options, Function onSuccess, Function onFailure); | ||
| external Auth2CurrentUser get currentUser; | ||
| } | ||
|
|
||
| @JS() | ||
| abstract class Auth2BasicProfile { | ||
| external String getId(); | ||
| external String getName(); | ||
| external String getGivenName(); | ||
| external String getFamilyName(); | ||
| external String getImageUrl(); | ||
| external String getEmail(); | ||
| } | ||
|
|
||
| @JS() | ||
| @anonymous | ||
| abstract class Auth2AuthResponse { | ||
| external String get access_token; | ||
| external String get id_token; | ||
| external String get scope; | ||
| external num get expires_in; | ||
| external num get first_issued_at; | ||
| external num get expires_at; | ||
| } | ||
|
|
||
| @JS() | ||
| abstract class Auth2AuthorizeResponse { | ||
| external String get access_token; | ||
| external String get id_token; | ||
| external String get code; | ||
| external String get scope; | ||
| external int get expires_in; | ||
| external int get first_issued_at; | ||
| external int get expires_at; | ||
| external String get error; | ||
| external String get error_subtype; | ||
| } | ||
|
|
||
| @JS() | ||
| abstract class GoogleUser { | ||
| external String getId(); | ||
| external bool isSignedIn(); | ||
| external String getHostedDomain(); | ||
| external String getGrantedScopes(); | ||
| external Auth2BasicProfile getBasicProfile(); | ||
| external Auth2AuthResponse getAuthResponse([bool includeAuthorizationData]); | ||
| external Future<Auth2AuthResponse> reloadAuthResponse(); | ||
| external bool hasGrantedScopes(String scopes); | ||
| external void grant(Auth2SignInOptions options); | ||
| // Offline access not implemented | ||
| external void disconnect(); | ||
| } | ||
|
|
||
| @JS() | ||
| @anonymous | ||
| // https://developers.google.com/identity/sign-in/web/reference#gapiauth2signinoptions | ||
| abstract class Auth2SignInOptions { | ||
| external factory Auth2SignInOptions({ | ||
| String prompt, | ||
| String scope, | ||
| String uxMode, | ||
| String redirectUri | ||
| }); | ||
|
|
||
| external String get prompt; | ||
| external String get scope; | ||
| @JS('ux_mode') | ||
| external String get uxMode; | ||
| @JS('redirect_uri') | ||
| external String get redirectUri; | ||
| } | ||
|
|
||
| @JS() | ||
| @anonymous | ||
| /// https://developers.google.com/identity/sign-in/web/reference#gapiauth2clientconfig | ||
| abstract class Auth2ClientConfig { | ||
| external factory Auth2ClientConfig({ | ||
| String clientId, | ||
| String cookiePolicy, | ||
| String scope, | ||
| bool fetchBasicProfile, | ||
| String hostedDomain, | ||
| String openIdRealm, | ||
| String uxMode, | ||
| String redirectUri | ||
| }); | ||
|
|
||
| @JS('client_id') | ||
| external String get clientId; | ||
|
|
||
| @JS('cookie_policy') | ||
| external String get cookiePolicy; | ||
|
|
||
| @JS('scope') | ||
| external String get scope; | ||
|
|
||
| @JS('fetch_basic_profile') | ||
| external bool get fetchBasicProfile; | ||
|
|
||
| @JS('hosted_domain') | ||
| external String get hostedDomain; | ||
|
|
||
| @JS('openid_realm') | ||
| external String get openIdRealm; | ||
|
|
||
| @JS('ux_mode') | ||
| external String get uxMode; | ||
|
|
||
| @JS('redirect_uri') | ||
| external String get redirectUri; | ||
| } | ||
|
|
||
| @JS() | ||
| @anonymous | ||
| /// https://developers.google.com/identity/sign-in/web/reference#gapiauth2authorizeconfig | ||
| abstract class Auth2AuthorizeConfig { | ||
| external factory Auth2AuthorizeConfig({ | ||
| String clientId, | ||
| String scope, | ||
| String responseType, | ||
| String prompt, | ||
| String cookiePolicy, | ||
| String hostedDomain, | ||
| String loginHint, | ||
| String openIdRealm, | ||
| bool includeGrantedScopes, | ||
| }); | ||
|
|
||
| @JS('client_id') | ||
| external String get clientId; | ||
|
|
||
| @JS('scope') | ||
| external String get scope; | ||
|
|
||
| @JS('response_type') | ||
| external String get responseType; | ||
|
|
||
| external String get prompt; | ||
|
|
||
| @JS('cookie_policy') | ||
| external String get cookiePolicy; | ||
|
|
||
| @JS('hosted_domain') | ||
| external String get hostedDomain; | ||
|
|
||
| @JS('login_hint') | ||
| external String get loginHint; | ||
|
|
||
| @JS('openid_realm') | ||
| external String get openIdRealm; | ||
|
|
||
| @JS('include_granted_scopes') | ||
| external bool get includeGrantedScopes; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.