{"id":13869,"date":"2024-07-19T23:25:19","date_gmt":"2024-07-19T14:25:19","guid":{"rendered":"https:\/\/www.ecomottblog.com\/?p=13869"},"modified":"2024-07-19T23:25:19","modified_gmt":"2024-07-19T14:25:19","slug":"%e3%82%b9%e3%83%9e%e3%83%9b%e3%82%a2%e3%83%97%e3%83%aa%e3%81%a7firebase-authentication%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e8%aa%8d%e8%a8%bc%e3%82%92%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/www.ecomottblog.com\/?p=13869","title":{"rendered":"\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u3067Firebase Authentication\u3092\u4f7f\u3063\u3066\u30ed\u30b0\u30a4\u30f3\u8a8d\u8a3c\u3092\u4f5c\u3063\u3066\u307f\u305f\u8a71"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01<br \/>\n\u30af\u30e9\u30a6\u30c9\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u90e8\u306e\u5927\u5ddd\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306fReact Native\u3068Firebase Authentication\u3092\u4f7f\u3063\u3066\u3001\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u306e\u30ed\u30b0\u30a4\u30f3\u8a8d\u8a3c\u3092\u4f5c\u6210\u3057\u305f\u8a71\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\uff01<\/p>\n<p><!--more--><\/p>\n<h2>Firebase Authentication\u3068\u306f\uff1f<\/h2>\n<p>\u300eFirebase Authentication\u300f\u306f\u3001Google\u304c\u63d0\u4f9b\u3059\u308b\u8a8d\u8a3c\u30b5\u30fc\u30d3\u30b9\u3067\u3001\u30a2\u30d7\u30ea\u3084\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u306e\u30e6\u30fc\u30b6\u30fc\u8a8d\u8a3c\u3092\u7c21\u5358\u304b\u3064\u5b89\u5168\u306b\u5b9f\u88c5\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n<h2>\u8a8d\u8a3c\u306e\u7a2e\u985e\u306b\u3064\u3044\u3066<\/h2>\n<h3>\u30cd\u30a4\u30c6\u30a3\u30d6\u306e\u30d7\u30ed\u30d0\u30a4\u30c0<\/h3>\n<ul>\n<li>\u30e1\u30fc\u30eb\/\u30d1\u30b9\u30ef\u30fc\u30c9<\/li>\n<li>\u96fb\u8a71\u756a\u53f7<\/li>\n<li>\u533f\u540d<\/li>\n<\/ul>\n<h3>\u30bd\u30fc\u30b7\u30e3\u30eb\u30d7\u30ed\u30d0\u30a4\u30c0<\/h3>\n<ul>\n<li>Google<\/li>\n<li>Facebook<\/li>\n<li>Twitter<\/li>\n<li>Microsoft<\/li>\n<li>Yahoo!<\/li>\n<li>Apple<\/li>\n<li>GitHub<\/li>\n<li>Game Center<\/li>\n<li>Play Games<\/li>\n<\/ul>\n<h3>\u30ab\u30b9\u30bf\u30e0\u30d7\u30ed\u30d0\u30a4\u30c0<\/h3>\n<ul>\n<li>OpenID Connect<\/li>\n<li>SAML<\/li>\n<\/ul>\n<h2>Firebase Authentication\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8\u306b\u3064\u3044\u3066<\/h2>\n<h3>\u30b7\u30f3\u30d7\u30eb\u306a\u5b9f\u88c5<\/h3>\n<p>\u8c4a\u5bcc\u306a\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001React Native\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u7c21\u5358\u306b\u7d71\u5408\u3067\u304d\u307e\u3059\u3002react-native-firebase\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u8907\u96d1\u306a\u8a2d\u5b9a\u3092\u7701\u7565\u3057\u3001\u8fc5\u901f\u306b\u8a8d\u8a3c\u6a5f\u80fd\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/rnfirebase.io\/\">react-native-firebase\u306e\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a><\/p>\n<h3>\u591a\u69d8\u306a\u8a8d\u8a3c\u65b9\u6cd5\u306e\u30b5\u30dd\u30fc\u30c8<\/h3>\n<p>\u524d\u8ff0\u306b\u8a18\u8f09\u3057\u3066\u3044\u308b\u5e45\u5e83\u3044\u8a8d\u8a3c\u65b9\u6cd5\u3092\u30e6\u30fc\u30b6\u30fc\u306b\u63d0\u4f9b\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h3>\n<p>\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea<\/p>\n<pre><code>import firebase from '@react-native-firebase\/app';\nimport auth from '@react-native-firebase\/auth';\nimport {Alert, Platform} from 'react-native';\nimport {GoogleSignin} from '@react-native-google-signin\/google-signin';\nimport {appleAuth} from '@invertase\/react-native-apple-authentication';\nimport Config from 'react-native-config';\nimport '@react-native-firebase\/functions';\n<\/code><\/pre>\n<p>Firebase\u306e\u521d\u671f\u5316<\/p>\n<pre><code>import firebase from '@react-native-firebase\/app';\nimport auth from '@react-native-firebase\/auth';\nimport {Alert, Platform} from 'react-native';\nimport {GoogleSignin} from '@react-native-google-signin\/google-signin';\nimport {appleAuth} from '@invertase\/react-native-apple-authentication';\nimport Config from 'react-native-config';\nimport '@react-native-firebase\/functions';\n\n\/\/ Firebase\u306e\u8a2d\u5b9a\uff08\u5b9f\u969b\u306e\u5024\u3092\u5165\u529b\u3059\u308b\uff09\nconst firebaseConfig = {\n  apiKey: Config.FIREBASE_API_KEY,\n  authDomain: Config.FIREBASE_AUTH_DOMAIN,\n  databaseURL: Config.FIREBASE_DATABASE_URL,\n  projectId: Config.FIREBASE_PROJECT_ID,\n  storageBucket: Config.FIREBASE_STORAGE_BUCKET,\n  messagingSenderId: Config.FIREBASE_MESSAGING_SENDER_ID,\n  appId: Config.FIREBASE_APP_ID,\n};\n\n\/\/ Firebase\u306e\u521d\u671f\u5316\nexport const firebaseInitializeApp =\n  Platform.OS === 'ios' ? firebase.initializeApp(firebaseConfig) : !auth.length ? firebase.initializeApp(firebaseConfig) : auth();\n\n\/\/ Firebase\u306e\u8a8d\u8a3c\u60c5\u5831\nconst firebaseAuth = firebase.auth();\n\n\/\/ Google\u8a8d\u8a3c\u306e\u8a2d\u5b9a\uff08\u5b9f\u969b\u306e\u5024\u3092\u5165\u529b\u3059\u308b\uff09\nGoogleSignin.configure({\n  webClientId: Config.FIREBASE_WEB_CLIENT_ID,\n});\n<\/code><\/pre>\n<h4>Google\u8a8d\u8a3c<\/h4>\n<pre><code>export const googleSignIn = async () =&gt; {\n  \/\/ Google \u306e\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u3092\u8868\u793a\u3057\u3066\u8a8d\u8a3c\u7528\u306e ID \u30c8\u30fc\u30af\u30f3\u3092\u53d6\u5f97\u3059\u308b\n  const user = await GoogleSignin.signIn();\n  const idToken = user.idToken;\n  if (idToken === null) {\n    console.log('\u30ed\u30b0\u30a4\u30f3\u5931\u6557', 'Google\u8a8d\u8a3c\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002');\n    return;\n  }\n  \/\/ \u53d6\u5f97\u3057\u305f\u8a8d\u8a3c\u60c5\u5831 (ID \u30c8\u30fc\u30af\u30f3) \u3092\u5143\u306b\u30b5\u30a4\u30f3\u30a4\u30f3\u3059\u308b\n  const credential = auth.GoogleAuthProvider.credential(idToken);\n  const userInfo = await firebaseAuth.signInWithCredential(credential).catch(error =&gt; {\n    console.log('\u30ed\u30b0\u30a4\u30f3\u5931\u6557', '\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u307e\u305f\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u306b\u8aa4\u308a\u304c\u3042\u308a\u307e\u3059\u3002');\n  });\n};\n<\/code><\/pre>\n<h4>Apple\u8a8d\u8a3c<\/h4>\n<pre><code>\/\/ Apple\u8a8d\u8a3c\u306b\u3088\u308b\u30b5\u30a4\u30f3\u30a4\u30f3\nexport const appleSignIn = async () =&gt; {\n  const appleAuthRequestResponse = await appleAuth.performRequest({\n    requestedOperation: appleAuth.Operation.LOGIN,\n    requestedScopes: [appleAuth.Scope.FULL_NAME, appleAuth.Scope.EMAIL],\n  });\n  if (!appleAuthRequestResponse.identityToken) {\n    console.log('\u30ed\u30b0\u30a4\u30f3\u5931\u6557', 'Apple\u8a8d\u8a3c\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002');\n    throw new Error('Apple Sign-In failed - no identify token returned');\n  }\n  const {identityToken, nonce} = appleAuthRequestResponse;\n  const appleCredential = auth.AppleAuthProvider.credential(identityToken, nonce);\n  const userInfo = await firebaseAuth.signInWithCredential(appleCredential).catch(error =&gt; {\n    console.log('\u30ed\u30b0\u30a4\u30f3\u5931\u6557', '\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u307e\u305f\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u306b\u8aa4\u308a\u304c\u3042\u308a\u307e\u3059\u3002');\n  });\n};\n<\/code><\/pre>\n<h4>Microsoft\u8a8d\u8a3c<\/h4>\n<pre><code>\/\/ Microsoft\u8a8d\u8a3c\u306b\u3088\u308b\u30b5\u30a4\u30f3\u30a4\u30f3\nexport const microsoftSignIn = async () =&gt; {\n  const provider = new firebase.auth.OAuthProvider('microsoft.com');\n  provider.addScope('offline_access');\n  provider.setCustomParameters({\n    prompt: '',\u3000\/\/\u3000\u5b9f\u969b\u306e\u5024\u3092\u5165\u529b\u3059\u308b\n    tenant: '',\u3000\/\/\u3000\u5b9f\u969b\u306e\u5024\u3092\u5165\u529b\u3059\u308b\n  });\n  const userInfo = await firebaseAuth.signInWithRedirect(provider).catch(error =&gt; {\n    console.log('\u30ed\u30b0\u30a4\u30f3\u5931\u6557', '\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u307e\u305f\u306f\u30d1\u30b9\u30ef\u30fc\u30c9\u306b\u8aa4\u308a\u304c\u3042\u308a\u307e\u3059\u3002');\n  });\n};\n\n<\/code><\/pre>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>Firebase Authentication\u306f\u3001\u30bb\u30ad\u30e5\u30a2\u306a\u30ed\u30b0\u30a4\u30f3\u8a8d\u8a3c\u3092\u5bb9\u6613\u306b\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u306b\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u958b\u767a\u3092\u3059\u308b\u969b\u306b\u3001\u305c\u3072\u5c0e\u5165\u3092\u691c\u8a0e\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\uff01<\/p>\n<h2>\u7d42\u308f\u308a\u306b<\/h2>\n<p>\u30a8\u30b3\u30e2\u30c3\u30c8\u3067\u306f\u4e00\u7dd2\u306b\u30e2\u30ce\u3065\u304f\u308a\u3092\u3057\u3066\u3044\u304f\u4ef2\u9593\u3092\u52df\u96c6\u4e2d\u3067\u3059\uff01<br \/>\n\u5f0a\u793e\u306b\u5c11\u3057\u3067\u3082\u8208\u5473\u304c\u3042\u308b\u65b9\u3001\u305c\u3072\u4e0b\u8a18\u306e\u63a1\u7528\u30da\u30fc\u30b8\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\uff01<\/p>\n<p><a href=\"https:\/\/www.ecomott.co.jp\/recruit\/\">\u52df\u96c6\u8981\u9805\uff08\u5f53\u793eHP\uff09<\/a><br \/>\n<a href=\"https:\/\/www.wantedly.com\/companies\/ecomott2\/projects\">Wantedly<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\uff01 \u30af\u30e9\u30a6\u30c9\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u90e8\u306e\u5927\u5ddd\u3067\u3059\u3002 \u4eca\u56de\u306fReact Native\u3068Firebase Authentication\u3092\u4f7f\u3063\u3066\u3001\u30b9\u30de\u30db\u30a2\u30d7\u30ea\u306e\u30ed\u30b0\u30a4\u30f3\u8a8d\u8a3c\u3092\u4f5c\u6210\u3057\u305f\u8a71\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\uff01<\/p>\n","protected":false},"author":36,"featured_media":13871,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[26,203,103,176,175,177,184,226],"_links":{"self":[{"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/13869"}],"collection":[{"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13869"}],"version-history":[{"count":23,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/13869\/revisions"}],"predecessor-version":[{"id":14117,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/posts\/13869\/revisions\/14117"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=\/wp\/v2\/media\/13871"}],"wp:attachment":[{"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecomottblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}