@@ -39,21 +39,32 @@ for capacitor 2.x.x use [instruction](https://github.com/CodetrixStudio/Capacito
3939
4040### WEB
4141
42- Add [ ` clientId ` ] ( https://developers.google.com/identity/sign-in/web/sign-in#specify_your_apps_client_id ) meta tag to head.
43-
44- ``` html
45- <meta name =" google-signin-client_id" content =" {your client id here}" />
46- ```
47-
4842Register plugin and manually initialize
4943
5044``` ts
5145import { GoogleAuth } from ' @codetrix-studio/capacitor-google-auth' ;
5246
5347// use hook after platform dom ready
54- GoogleAuth .init ();
48+ GoogleAuth .initialize ({
49+ client_id: ' CLIENT_ID.apps.googleusercontent.com' ,
50+ scopes: [' profile' , ' email' ],
51+ grantOfflineAccess: true ,
52+ });
53+ ```
54+
55+ or if need use meta tags
56+
57+ ``` html
58+ <meta name =" google-signin-client_id" content =" {your client id here}" />
59+ <meta name =" google-signin-scope" content =" profile email" />
5560```
5661
62+ #### Options
63+
64+ - ` client_id ` - The app's client ID, found and created in the Google Developers Console.
65+ - ` scopes ` – same as [ Configure] ( #Configure ) scopes
66+ - ` grantOfflineAccess ` – boolean, default ` false ` , Set if your application needs to refresh access tokens when the user is not present at the browser.
67+
5768Use it
5869
5970``` ts
@@ -72,7 +83,7 @@ constructor() {
7283
7384initializeApp () {
7485 this .platform .ready ().then (() => {
75- GoogleAuth .init ()
86+ GoogleAuth .initialize ()
7687 })
7788}
7889```
@@ -97,7 +108,7 @@ import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
97108export default defineComponent ({
98109 setup() {
99110 onMounted (() => {
100- GoogleAuth .init ();
111+ GoogleAuth .initialize ();
101112 });
102113
103114 const logIn = async () => {
@@ -111,32 +122,37 @@ export default defineComponent({
111122 },
112123});
113124```
125+
114126or see more [ CapacitorGoogleAuth-Vue3-example] ( https://github.com/reslear/CapacitorGoogleAuth-Vue3-example )
115127
116128### iOS
117129
1181301 . Create in Google cloud console credential ** Client ID for iOS** and get ** Client ID** and ** iOS URL scheme**
119131
1201322 . Add ** identifier** ` REVERSED_CLIENT_ID ` as ** URL schemes** to ` Info.plist ` from ** iOS URL scheme** <br >
121- (Xcode: App - Targets/App - Info - URL Types, click plus icon)
122-
123- 3 . Set ** Client ID** one of the ways:
124- 1 . Set in ` capacitor.config.json `
125- - ` iosClientId ` - specific key for iOS
126- - ` clientId ` - or common key for Android and iOS
127- 3 . Download ` GoogleService-Info.plist ` file with ` CLIENT_ID ` and copy to ** ios/App/App** necessarily through Xcode for indexing.
133+ (Xcode: App - Targets/App - Info - URL Types, click plus icon)
128134
135+ 3 . Set ** Client ID** one of the ways:
136+ 1 . Set in ` capacitor.config.json `
137+ - ` iosClientId ` - specific key for iOS
138+ - ` clientId ` - or common key for Android and iOS
139+ 2 . Download ` GoogleService-Info.plist ` file with ` CLIENT_ID ` and copy to ** ios/App/App** necessarily through Xcode for indexing.
129140
141+ plugin first use ` iosClientId ` if not found use ` clientId ` if not found use value ` CLIENT_ID ` from file ` GoogleService-Info.plist `
130142
131143### Android
132144
133145Set ** Client ID** :
134146
1351471 . In ` capacitor.config.json `
136- - ` androidClientId ` - specific key for Android
137- - ` clientId ` - or common key for Android and iOS
148+
149+ - ` androidClientId ` - specific key for Android
150+ - ` clientId ` - or common key for Android and iOS
138151
1391522 . or set inside your ` strings.xml `
153+
154+ plugin first use ` androidClientId ` if not found use ` clientId ` if not found use value ` server_client_id ` from file ` strings.xml `
155+
140156``` xml
141157<resources >
142158 <string name =" server_client_id" >Your Web Client Key</string >
@@ -159,6 +175,12 @@ this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
159175
160176## Configure
161177
178+ | Name | Type | Default | Description |
179+ | ------------------------ | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
180+ | scopes | string[ ] | [ ] | Scopes that you might need to request to access Google APIs<br >https://developers.google.com/identity/protocols/oauth2/scopes <br ><br >example: ` ["profile", "email"] ` |
181+ | serverClientId | string | '' | This is used for offline access and serverside handling<br ><br >example: ` xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com ` |
182+ | forceCodeForRefreshToken | boolean | false | Force user to select email address to regenerate AuthCode <br >used to get a valid refreshtoken (work on iOS and Android) |
183+
162184Provide configuration in root ` capacitor.config.json `
163185
164186``` json
@@ -173,10 +195,33 @@ Provide configuration in root `capacitor.config.json`
173195}
174196```
175197
176- Note : ` forceCodeForRefreshToken ` force user to select email address to regenerate AuthCode used to get a valid refreshtoken (work on iOS and Android) (This is used for offline access and serverside handling)
198+ or in ` capacitor.config.ts `
199+
200+ ``` ts
201+ /// <reference types = " '@codetrix-studio/capacitor-google-auth'" />
202+
203+ const config: CapacitorConfig = {
204+ plugins: {
205+ GoogleAuth: {
206+ scopes: [' profile' , ' email' ],
207+ serverClientId: ' xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com' ,
208+ forceCodeForRefreshToken: true ,
209+ },
210+ },
211+ };
212+
213+ export default config ;
214+ ```
177215
178216## Migration guide
179217
218+ #### Migrate from 3.0.2 to 3.1.0
219+
220+ ``` diff
221+ - GoogleAuth.init()
222+ + GoogleAuth.initialize()
223+ ```
224+
180225#### Migrate from 2 to 3
181226
182227After [ migrate to Capcitor 3] ( https://capacitorjs.com/docs/updating/3-0 ) updating you projects, see diff:
0 commit comments