-
-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// @flow | ||
import * as React from 'react'; | ||
import { typeof View } from 'react-native'; | ||
|
||
export type ConfigureParams = $ReadOnly<{| | ||
iosClientId?: string, | ||
googleServicePlistPath?: string, | ||
offlineAccess?: boolean, | ||
webClientId?: string, | ||
scopes?: string[], | ||
hostedDomain?: string, | ||
forceCodeForRefreshToken?: boolean, | ||
accountName?: string, | ||
openIdRealm?: string, | ||
profileImageSize?: number, | ||
|}>; | ||
|
||
export type SignInParams = $ReadOnly<{| | ||
loginHint?: string, | ||
|}>; | ||
|
||
export type AddScopesParams = $ReadOnly<{| | ||
/** | ||
* The Google API scopes to request access to. Default is email and profile. | ||
*/ | ||
scopes?: string[], | ||
|}>; | ||
|
||
export type GoogleSigninButtonProps = $ReadOnly<{| | ||
...React.ElementConfig<View>, | ||
size?: number, | ||
color?: string, | ||
disabled?: boolean, | ||
onPress?: () => any, | ||
|}>; | ||
|
||
declare export class GoogleSigninButton extends React.Component<GoogleSigninButtonProps> { | ||
static Size: { | ||
Icon: number, | ||
Standard: number, | ||
Wide: number, | ||
}; | ||
|
||
static Color: { | ||
Auto: string, | ||
Light: string, | ||
Dark: string, | ||
}; | ||
} | ||
|
||
export type HasPlayServicesParams = $ReadOnly<{| | ||
showPlayServicesUpdateDialog: boolean, | ||
|}>; | ||
|
||
export type User = {| | ||
user: {| | ||
id: string, | ||
name: ?string, // full name | ||
email: string, | ||
photo: ?string, // url | ||
familyName: ?string, | ||
givenName: ?string, | ||
|}, | ||
scopes: string[], // on iOS this is empty array if no additional scopes are defined | ||
idToken: string, | ||
/** | ||
* Not null only if a valid webClientId and offlineAccess: true was | ||
* specified in configure(). | ||
*/ | ||
serverAuthCode: ?string, | ||
|}; | ||
|
||
// Android Status codes: https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes | ||
type StatusCodes = $ReadOnly<{ | ||
SIGN_IN_CANCELLED: string, | ||
IN_PROGRESS: string, | ||
PLAY_SERVICES_NOT_AVAILABLE: string, | ||
SIGN_IN_REQUIRED: string, | ||
}>; | ||
|
||
declare export var statusCodes: StatusCodes; | ||
|
||
// the functions are not static in fact, but the module exports a | ||
// singleton instance of the class; not the class itself | ||
// using static keyword works well for this case | ||
declare export class GoogleSignin { | ||
static hasPlayServices: (params?: HasPlayServicesParams) => Promise<boolean>; | ||
static configure: (params?: ConfigureParams) => void; | ||
static signInSilently: () => Promise<User>; | ||
static signIn: (params?: SignInParams) => Promise<User>; | ||
static addScopes: (params: AddScopesParams) => Promise<User | null>; | ||
static signOut: () => Promise<null>; | ||
static revokeAccess: () => Promise<null>; | ||
static hasPreviousSignIn: () => boolean; | ||
static getCurrentUser(): User | null; | ||
static clearCachedAccessToken(token: string): Promise<null>; | ||
static getTokens(): Promise<{ idToken: string, accessToken: string }>; | ||
} |