在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):CodetrixStudio/CapacitorGoogleAuth开源软件地址(OpenSource Url):https://github.com/CodetrixStudio/CapacitorGoogleAuth开源编程语言(OpenSource Language):Java 36.0%开源软件介绍(OpenSource Introduction):CapacitorGoogleAuthCapacitor plugin for Google Auth. ContributionsPRs are welcome and much appreciated that keeps this plugin up to date with Capacitor and official Google Auth platform library feature parity. Try to follow good code practices. You can even help keeping the included demo updated. PRs for features that are not aligned with the official Google Auth library are discouraged. (We are beginner-friendly here) Install1. Install packagenpm i --save @codetrix-studio/capacitor-google-auth
# or for Capacitor 2.x.x
npm i --save @codetrix-studio/[email protected] 2. Update capacitor depsnpx cap update 3. Migrate from 2 to 3 versionif your migrate from Capacitor 2 to Capacitor 3 see instruction for migrate plugin to new version Usagefor capacitor 2.x.x use instruction WEBRegister plugin and manually initialize import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
// use hook after platform dom ready
GoogleAuth.initialize({
clientId: 'CLIENT_ID.apps.googleusercontent.com',
scopes: ['profile', 'email'],
grantOfflineAccess: true,
}); or if need use meta tags <meta name="google-signin-client_id" content="{your client id here}" />
<meta name="google-signin-scope" content="profile email" /> Options
Use it GoogleAuth.signIn(); AngularFire2init hook // app.component.ts
constructor() {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
GoogleAuth.initialize()
})
} sign in function async googleSignIn() {
let googleUser = await GoogleAuth.signIn();
const credential = auth.GoogleAuthProvider.credential(googleUser.authentication.idToken);
return this.afAuth.auth.signInAndRetrieveDataWithCredential(credential);
} Vue 3// App.vue
import { defineComponent, onMounted } from 'vue';
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
export default defineComponent({
setup() {
onMounted(() => {
GoogleAuth.initialize();
});
const logIn = async () => {
const response = await GoogleAuth.signIn();
console.log(response);
};
return {
logIn,
};
},
}); or see more CapacitorGoogleAuth-Vue3-example iOS
plugin first use AndroidSet Client ID :
plugin first use <resources>
<string name="server_client_id">Your Web Client Key</string>
</resources> Import package inside your import com.codetrixstudio.capacitor.GoogleAuth.GoogleAuth; Register plugin inside your this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
add(GoogleAuth.class);
}}); Configure
Provide configuration in root {
"plugins": {
"GoogleAuth": {
"scopes": ["profile", "email"],
"serverClientId": "xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com",
"forceCodeForRefreshToken": true
}
}
} or in /// <reference types="'@codetrix-studio/capacitor-google-auth'" />
const config: CapacitorConfig = {
plugins: {
GoogleAuth: {
scopes: ['profile', 'email'],
serverClientId: 'xxxxxx-xxxxxxxxxxxxxxxxxx.apps.googleusercontent.com',
forceCodeForRefreshToken: true,
},
},
};
export default config; Migration guideMigrate from 3.0.2 to 3.1.0- GoogleAuth.init()
+ GoogleAuth.initialize() Migrate from 2 to 3After migrate to Capcitor 3 updating you projects, see diff: WEB- import "@codetrix-studio/capacitor-google-auth";
- import { Plugins } from '@capacitor/core';
+ import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth'
- Plugins.GoogleAuth.signIn();
+ GoogleAuth.init()
+ GoogleAuth.signIn() |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论