muerwre.github.io/docs/frontend/react-native/oauth2-login/index.html
2024-03-21 11:24:25 +00:00

6 lines
No EOL
29 KiB
HTML

<!DOCTYPE html>
<html data-head-attrs="">
<head><title>OAuth2 Login • Obsidian Garden</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><script src="https://anal.vault48.org/script.js" data-website-id="7d587423-ffda-4732-a99d-6cf60d5c9a8a" async></script><meta name="description" content="Use #oauth2 login with React-Native"><meta name="head:count" content="4"><link rel="modulepreload" href="/frontend/react-native/oauth2-login/_payload.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/entry.0ac1105a.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/default.5ee93473.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/LayoutMainMenuToggle.16bf42cd.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/LayoutMainMenuToggle.vue_used_vue_type_style_index_0_lang.module.fbcd3219.js"><link rel="preload" as="style" href="/nuxt/LayoutMainMenuToggle.vue_used_vue_type_style_index_0_lang.17e7aae7.css"><link rel="modulepreload" as="script" crossorigin href="/nuxt/LayoutMainMenu.25f8974f.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/navigation.249efedf.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/content.887f506f.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/LayoutThemeToggle.c652c3fc.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/LayoutThemeToggle.vue_used_vue_type_style_index_0_lang.module.2bd846bf.js"><link rel="preload" as="style" href="/nuxt/LayoutThemeToggle.vue_used_vue_type_style_index_0_lang.cfa40af4.css"><link rel="modulepreload" as="script" crossorigin href="/nuxt/LayoutFooter.b670897a.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/_...slug_.848f1208.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/HomeReference.77442693.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/ProseP.dafff666.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/ProseH2.4b62290f.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/ProseA.189aad8b.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/ProseCodeInline.d05be2e8.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/ProseH3.51f54a19.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/ProseCode.724640cc.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/UiIconCopy.42c3636a.js"><link rel="modulepreload" as="script" crossorigin href="/nuxt/ProseCode.vue_used_vue_type_style_index_1_lang.module.230a312a.js"><link rel="preload" as="style" href="/nuxt/ProseCode.vue_used_vue_type_style_index_1_lang.24930a5d.css"><link rel="prefetch" as="script" crossorigin href="/nuxt/client-db.f0fc27c4.js"><link rel="prefetch" as="script" crossorigin href="/nuxt/web-socket.e1ee3b6d.js"><link rel="prefetch" as="script" crossorigin href="/nuxt/error-component.930b5d89.js"><link rel="prefetch" as="script" crossorigin href="/nuxt/landing.7b145cd1.js"><link rel="prefetch" as="style" href="/nuxt/LayoutHeader.vue_used_vue_type_style_index_0_lang.b2295632.css"><link rel="prefetch" as="script" crossorigin href="/nuxt/LayoutHeader.ce49b430.js"><link rel="prefetch" as="script" crossorigin href="/nuxt/LayoutHeader.vue_used_vue_type_style_index_0_lang.module.57d4f89f.js"><link rel="prefetch" as="style" href="/nuxt/entry.cc7e4146.css"><link rel="prefetch" as="image" type="image/svg+xml" href="/nuxt/logo.d91c5032.svg"><link rel="stylesheet" href="/nuxt/LayoutMainMenuToggle.vue_used_vue_type_style_index_0_lang.17e7aae7.css"><link rel="stylesheet" href="/nuxt/LayoutThemeToggle.vue_used_vue_type_style_index_0_lang.cfa40af4.css"><link rel="stylesheet" href="/nuxt/ProseCode.vue_used_vue_type_style_index_1_lang.24930a5d.css"><style>._grid_1ipws_1{display:grid;grid-template-columns:360px auto;width:100%}@media (max-width:1024px){._grid_1ipws_1{grid-template-columns:33vw auto}}@media (max-width:768px){._grid_1ipws_1{grid-template-columns:auto}}._main_1ipws_17{display:flex;flex-direction:column;height:100%;min-width:0;position:relative;z-index:1}._sidebar_1ipws_26{background-color:var(--color-menu-background)}@media (max-width:768px){._sidebar_1ipws_26{background-color:var(--color-menu-overlay-background);opacity:0;position:fixed;transition:opacity .5s;visibility:hidden;width:100%;z-index:2}._sidebar_1ipws_26._active_1ipws_39{opacity:1;visibility:visible}}._menu_1ipws_45{background-color:var(--color-menu-background);height:100vh;max-width:400px;min-width:0;overflow:auto;padding:40px 30px;position:sticky;top:0}@media (max-width:768px){._menu_1ipws_45{transform:translate(-40px);transition:transform .25s .1s}._active_1ipws_39 ._menu_1ipws_45{transform:translate(0)}}._menu_toggle_1ipws_65{border-radius:0 0 8px 0;left:13px;position:fixed;top:13px;transform:translate(0);transition:all .25s;visibility:hidden;z-index:4}@media (max-width:768px){._menu_toggle_1ipws_65{right:0;transform:translate(0);visibility:visible}}._menu_toggle_1ipws_65._active_1ipws_39,._menu_toggle_1ipws_65._shifted_1ipws_82{transform:translate(-13px,-13px)}._menu_toggle_1ipws_65._shifted_1ipws_82{background:var(--color-menu-background)}._footer_1ipws_89{margin-top:40px}._content_1ipws_93{height:100%;width:100%}@media (max-width:768px){._content_1ipws_93{padding-top:40px}}</style><style>._wrapper_vom09_1{display:flex;flex:1;flex-direction:column;height:100%;padding-top:40px}@media (max-width:1024px){._wrapper_vom09_1{padding-top:10px}}._content_vom09_14{flex:1}._footer_vom09_18{border-top:1px solid var(--color-line);margin-top:60px;padding:10px}._theme_toggle_vom09_24{stroke:currentColor;stroke-width:.5px;position:absolute;right:20px;top:20px;z-index:12}@media (max-width:768px){._theme_toggle_vom09_24{stroke-width:1.5px;right:16px;top:16px}}</style><style>._content_1gz79_1{margin:auto;max-width:min(1280px,100vw);padding:0 40px}@media (max-width:1024px){._content_1gz79_1{padding:0 40px}}@media (max-width:768px){._content_1gz79_1{padding:0 20px}}</style><style>._container_192pu_1{position:relative}._container_192pu_1._secondary_192pu_4{padding:7px 2px 0}._container_192pu_1._secondary_192pu_4:before{background-color:var(--color-menu-line);bottom:13px;content:" ";left:-16px;position:absolute;top:-22px;width:1px}._container_192pu_1._secondary_192pu_4:first-child:before{top:-4px}._container_192pu_1._secondary_192pu_4:last-child:before{bottom:auto;height:40px}._row_192pu_24{padding:3px 2px;position:relative}._row_192pu_24:before{background-color:var(--color-menu-line);bottom:13px;content:" ";left:-16px;position:absolute;top:-14px;width:1px}._row_192pu_24:first-child:before{top:-4px}._row_192pu_24:last-child:before{bottom:auto;height:30px}._row_192pu_24:only-child:before{height:19px}._heading_192pu_48{align-items:center;color:var(--color-menu-title);display:flex;font-weight:600;position:relative;text-transform:uppercase}._secondary_192pu_4 ._heading_192pu_48:before{background-color:var(--color-menu-line);content:" ";height:1px;left:-17px;position:absolute;top:.6em;width:10px}._link_192pu_66{color:var(--color-menu-link);line-height:1.4em;position:relative;text-decoration:none}._link_192pu_66:before{background-color:var(--color-menu-line);content:" ";height:1px;left:-17px;position:absolute;top:.6em;width:10px}._link_192pu_66._active_192pu_81{color:var(--color-menu-link-active);font-weight:700}._children_192pu_86{margin:10px 3px;padding:0 0 0 16px;position:relative}</style><link rel="stylesheet" href="/nuxt/entry.cc7e4146.css" media="print" onload="this.media='all'; this.onload=null;"><script>const w=window,de=document.documentElement,knownColorSchemes=["dark","light"],preference=window.localStorage.getItem("nuxt-color-mode")||"dark";let value=preference==="system"?getColorScheme():preference;const forcedColorMode=de.getAttribute("data-color-mode-forced");forcedColorMode&&(value=forcedColorMode),addColorScheme(value),w["__NUXT_COLOR_MODE__"]={preference,value,getColorScheme,addColorScheme,removeColorScheme};function addColorScheme(e){const o=""+e+"",t="";de.classList?de.classList.add(o):de.className+=" "+o,t&&de.setAttribute("data-"+t,e)}function removeColorScheme(e){const o=""+e+"",t="";de.classList?de.classList.remove(o):de.className=de.className.replace(new RegExp(o,"g"),""),t&&de.removeAttribute("data-"+t)}function prefersColorScheme(e){return w.matchMedia("(prefers-color-scheme"+e+")")}function getColorScheme(){if(w.matchMedia&&prefersColorScheme("").media!=="not all"){for(const e of knownColorSchemes)if(prefersColorScheme(":"+e).matches)return e}return"light"}
</script></head>
<body data-head-attrs=""><div id="__nuxt"><div class="_grid_1ipws_1" hastransition="true"><button class="_menu_toggle_1ipws_65 _button_5opgq_1 _menu_toggle_1ipws_65"><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" fill="#ffffff" class="_hamburger_5opgq_9"><rect x="0" y="3" width="24" height="2"></rect><rect x="0" y="11" width="24" height="2"></rect><rect x="0" y="19" width="24" height="2"></rect></svg></button><div class="_sidebar_1ipws_26"><div class="_menu_1ipws_45"><nav><div class="_logo_kmqkz_8"><a href="/" class=""><div class="_title_kmqkz_29">Obsidian Garden</div><div class="_subtitle_kmqkz_35">by muerwre</div></a></div><div class="_section_title_kmqkz_1">Cheatsheet</div><!--[--><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Blockchain</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/blockchain/common-typescript-examples" class="_link_192pu_66">Common Typescript Examples</a></div><div class="_row_192pu_24"><a href="/blockchain/smart-contracts" class="_link_192pu_66">Smart Contracts</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Css</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/css/automatic-grid-like-masonry-with-pure-css" class="_link_192pu_66">Automatic Grid Like Masonry With Pure CSS</a></div><div class="_row_192pu_24"><a href="/css/sass-nth-child-iterate-mixin" class="_link_192pu_66">Sass Nth Child Iterate Mixin</a></div><div class="_row_192pu_24"><a href="/css/test-if-browser-supports-css-rules" class="_link_192pu_66">Test If Browser Supports CSS Rules</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Docker</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/docker/building-static-pages-with-docker" class="_link_192pu_66">Building Static Pages With Docker</a></div><div class="_row_192pu_24"><a href="/docker/common-things-with-docker-mailserver" class="_link_192pu_66">Common Things With Docker Mailserver</a></div><div class="_row_192pu_24"><a href="/docker/drone-ci" class="_link_192pu_66">Drone Ci</a></div><div class="_row_192pu_24"><a href="/docker/github-pages-with-drone-ci" class="_link_192pu_66">Github Pages With Drone Ci</a></div><div class="_row_192pu_24"><a href="/docker/private-docker-registry" class="_link_192pu_66">Private Docker Registry</a></div><div class="_row_192pu_24"><a href="/docker/refresh-containers-on-pull" class="_link_192pu_66">Refresh Containers On Pull</a></div><div class="_row_192pu_24"><a href="/docker/seed-dump-inside-docker" class="_link_192pu_66">Seed Dump Inside Docker</a></div><div class="_row_192pu_24"><a href="/docker/wait-for-mysql" class="_link_192pu_66">Wait For Mysql</a></div><div class="_row_192pu_24"><a href="/docker/wait-for-redis" class="_link_192pu_66">Wait For Redis</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Frontend</div><div class="_children_192pu_86"><!--[--><div class="_container_192pu_1 _secondary_192pu_4"><div class="_heading_192pu_48">React Native</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a aria-current="page" href="/frontend/react-native/oauth2-login" class="router-link-active _active_192pu_81 _link_192pu_66">OAuth2 Login</a></div><div class="_row_192pu_24"><a href="/frontend/react-native/preserve-flatlist-scroll-position-in-react-native" class="_link_192pu_66">Preserve FlatList Scroll Position In React Native</a></div><div class="_row_192pu_24"><a href="/frontend/react-native/useful-comands" class="_link_192pu_66">Useful Comands</a></div><!--]--></div></div><div class="_container_192pu_1 _secondary_192pu_4"><div class="_heading_192pu_48">React</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/frontend/react/axios-refresh-token-on-react" class="_link_192pu_66">Axios Refresh Token On React</a></div><div class="_row_192pu_24"><a href="/frontend/react/axios-with-abortcontroller" class="_link_192pu_66">Axios With AbortController</a></div><div class="_row_192pu_24"><a href="/frontend/react/detect-hook-deps-changes-with-usewhatschanged" class="_link_192pu_66">Detect Hook Deps Changes With UseWhatsChanged</a></div><!--]--></div></div><div class="_container_192pu_1 _secondary_192pu_4"><div class="_heading_192pu_48">Vue</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/frontend/vue/adding-global-properties-to-component" class="_link_192pu_66">Adding Global Properties To Component</a></div><div class="_row_192pu_24"><a href="/frontend/vue/make-nuxt-handle-obsidian-highlights" class="_link_192pu_66">Make Nuxt Handle Obsidian Highlights</a></div><!--]--></div></div><div class="_container_192pu_1 _secondary_192pu_4"><div class="_heading_192pu_48">Webgl</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/frontend/webgl/basics-of-webgl-(drawing-a-cube)" class="_link_192pu_66">Basics Of WebGL (Drawing A Cube)</a></div><div class="_row_192pu_24"><a href="/frontend/webgl/fragment-shaders" class="_link_192pu_66">Fragment Shaders</a></div><div class="_row_192pu_24"><a href="/frontend/webgl/rendering-without-blocking-in-a-worker" class="_link_192pu_66">Rendering Without Blocking In A Worker</a></div><div class="_row_192pu_24"><a href="/frontend/webgl/vertex-shaders" class="_link_192pu_66">Vertex Shaders</a></div><!--]--></div></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Git</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/git/force-git-to-use-https" class="_link_192pu_66">Force Git To Use HTTPS</a></div><div class="_row_192pu_24"><a href="/git/git-aliases-and-useful-commands" class="_link_192pu_66">Git Aliases And Useful Commands</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Golang</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/golang/i18n-in-golang" class="_link_192pu_66">I18n In Golang</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Graphql</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/graphql/apollo-client-pagination" class="_link_192pu_66">Apollo Client Pagination</a></div><div class="_row_192pu_24"><a href="/graphql/refresh-token-in-apollo-client" class="_link_192pu_66">Refresh Token In Apollo Client</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Linux</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/linux/certbot-well-known-auto-renew" class="_link_192pu_66">Certbot Well Known Auto Renew</a></div><div class="_row_192pu_24"><a href="/linux/find-out-who-uses-swap" class="_link_192pu_66">Find Out Who Uses Swap</a></div><div class="_row_192pu_24"><a href="/linux/fixing-lagging-usb-headphones" class="_link_192pu_66">Fixing Lagging USB Headphones</a></div><div class="_row_192pu_24"><a href="/linux/gitea-for-git-hosting" class="_link_192pu_66">Gitea For Git Hosting</a></div><div class="_row_192pu_24"><a href="/linux/google-photos-alternative-with-photoprism" class="_link_192pu_66">Google Photos Alternative With Photoprism</a></div><div class="_row_192pu_24"><a href="/linux/linux-on-asus-zenbook-um3402-ya" class="_link_192pu_66">Linux On Asus Zenbook UM3402 YA</a></div><div class="_row_192pu_24"><a href="/linux/resume-or-start-screen-session" class="_link_192pu_66">Resume Or Start Screen Session</a></div><div class="_row_192pu_24"><a href="/linux/rsync-file-with-ssh" class="_link_192pu_66">Rsync File With SSH</a></div><div class="_row_192pu_24"><a href="/linux/setting-up-nginx" class="_link_192pu_66">Setting Up NGINX</a></div><div class="_row_192pu_24"><a href="/linux/ssh" class="_link_192pu_66">SSH</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Obsidian</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/obsidian/self-hosted-obsidian-sync-with-couchdb" class="_link_192pu_66">Self Hosted Obsidian Sync With CouchDB</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Sql</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/sql/mysql-and-mariadb-setup" class="_link_192pu_66">MySQL And MariaDB Setup</a></div><div class="_row_192pu_24"><a href="/sql/postgress-setup" class="_link_192pu_66">Postgress Setup</a></div><!--]--></div></div></div><div class="_row_kmqkz_25"><div class="_container_192pu_1"><div class="_heading_192pu_48">Typescript</div><div class="_children_192pu_86"><!--[--><div class="_row_192pu_24"><a href="/typescript/add-global-variable-to-window" class="_link_192pu_66">Add Global Variable To Window</a></div><div class="_row_192pu_24"><a href="/typescript/flatten-object-with-periods" class="_link_192pu_66">Flatten Object With Periods</a></div><div class="_row_192pu_24"><a href="/typescript/type-guards" class="_link_192pu_66">Type Guards</a></div><!--]--></div></div></div><!--]--></nav></div></div><div class="_main_1ipws_17"><div class="_content_1ipws_93"><div class="_wrapper_vom09_1" hastransition="true"><div class="_content_vom09_14"><button class="_theme_toggle_vom09_24 _button_jz7in_1 _theme_toggle_vom09_24"><span></span></button><!--[--><!--[--><main class="_content_1gz79_1"><!--[--><h1>OAuth2 Login</h1><article><div><p><!--[-->Use #oauth2 login with React-Native<!--]--></p><h2 id="common-oauth2-providers"><a href="#common-oauth2-providers"><!--[-->Common OAuth2 providers<!--]--></a></h2><p><!--[-->Can be handled by <a href="/frontend/react-native/react-native-app-auth" class=""><!--[-->react-native-app-auth<!--]--></a> by redirecting to url <code><!--[-->com.yourapp://oauth2provider<!--]--></code>.<!--]--></p><h3 id="example-for-google"><a href="#example-for-google"><!--[-->Example for #Google<!--]--></a></h3><div class="_wrapper_1pe7v_1"><button class="_language_1pe7v_9"><span class="_icon_1pe7v_5"><svg xmlns="http://www.w3.org/2000/svg" height="12" viewbox="0 0 24 24" width="12" fill="currentColor"><path d="M0 0h24v24H0z" fill="none"></path><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"></path></svg></span><span>typescript</span></button><!--[--><pre><code><span class="line"><span class="ct-eaff2e">import</span><span class="ct-f06536"> { </span><span class="ct-868453">authorize</span><span class="ct-f06536"> } </span><span class="ct-eaff2e">from</span><span class="ct-f06536"> </span><span class="ct-e50739">&#39;react-native-app-auth&#39;</span><span class="ct-f06536">;</span></span><span class="line"></span><span class="line"><span class="ct-6e5da4">const</span><span class="ct-f06536"> </span><span class="ct-b47256">GOOGLE_OAUTH_CLIENT</span><span class="ct-f06536"> </span><span class="ct-eaff2e">=</span><span class="ct-f06536"> </span><span class="ct-e50739">&#39;...&#39;</span><span class="ct-f06536">;</span></span><span class="line"></span><span class="line"><span class="ct-719333">// ...</span></span><span class="line"><span class="ct-6e5da4">const</span><span class="ct-f06536"> </span><span class="ct-b47256">authState</span><span class="ct-f06536"> </span><span class="ct-eaff2e">=</span><span class="ct-f06536"> </span><span class="ct-eaff2e">await</span><span class="ct-f06536"> </span><span class="ct-d5d2b2">authorize</span><span class="ct-f06536">({</span></span><span class="line"><span class="ct-f06536"> issuer: </span><span class="ct-e50739">&#39;https://accounts.google.com&#39;</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536"> clientId: </span><span class="ct-e50739">`${</span><span class="ct-b47256">GOOGLE_OAUTH_CLIENT</span><span class="ct-e50739">}.apps.googleusercontent.com`</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536"> redirectUrl: </span><span class="ct-e50739">`com.yourapp:/oauth2redirect/google`</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536"> scopes: [</span><span class="ct-e50739">&#39;openid&#39;</span><span class="ct-f06536">, </span><span class="ct-e50739">&#39;profile&#39;</span><span class="ct-f06536">],</span></span><span class="line"><span class="ct-f06536"> dangerouslyAllowInsecureHttpRequests: </span><span class="ct-919484">true</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536">});</span></span></code></pre><!--]--></div><h3 id="example-for-yandex"><a href="#example-for-yandex"><!--[-->Example for #Yandex<!--]--></a></h3><div class="_wrapper_1pe7v_1"><button class="_language_1pe7v_9"><span class="_icon_1pe7v_5"><svg xmlns="http://www.w3.org/2000/svg" height="12" viewbox="0 0 24 24" width="12" fill="currentColor"><path d="M0 0h24v24H0z" fill="none"></path><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"></path></svg></span><span>typescript</span></button><!--[--><pre><code><span class="line"><span class="ct-6e5da4">const</span><span class="ct-f06536"> </span><span class="ct-b47256">YANDEX_OAUTH_CLIENT</span><span class="ct-f06536"> </span><span class="ct-eaff2e">=</span><span class="ct-f06536"> </span><span class="ct-e50739">&#39;...&#39;</span><span class="ct-f06536">;</span></span><span class="line"><span class="ct-6e5da4">const</span><span class="ct-f06536"> </span><span class="ct-b47256">YANDEX_OAUTH_SECRET</span><span class="ct-f06536"> </span><span class="ct-eaff2e">=</span><span class="ct-f06536"> </span><span class="ct-e50739">&#39;...&#39;</span><span class="ct-f06536">; </span><span class="ct-719333">// better hide it somehow</span></span><span class="line"><span class="ct-6e5da4">const</span><span class="ct-f06536"> </span><span class="ct-b47256">APP_ID</span><span class="ct-f06536"> </span><span class="ct-eaff2e">=</span><span class="ct-f06536"> </span><span class="ct-e50739">&#39;com.yourapp&#39;</span><span class="ct-f06536">;</span></span><span class="line"></span><span class="line"><span class="ct-6e5da4">const</span><span class="ct-f06536"> </span><span class="ct-b47256">authState</span><span class="ct-f06536"> </span><span class="ct-eaff2e">=</span><span class="ct-f06536"> </span><span class="ct-eaff2e">await</span><span class="ct-f06536"> </span><span class="ct-d5d2b2">authorize</span><span class="ct-f06536">({</span></span><span class="line"><span class="ct-f06536"> serviceConfiguration: {</span></span><span class="line"><span class="ct-f06536"> authorizationEndpoint: </span><span class="ct-e50739">`https://oauth.yandex.ru/authorize?response_type=code&amp;client_id=${</span><span class="ct-b47256">YANDEX_OAUTH_CLIENT</span><span class="ct-e50739">}&amp;redirect_uri=${</span><span class="ct-b47256">APP_ID</span><span class="ct-e50739">}:/oauth2redirect`</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536"> </span><span class="ct-719333">// TODO: replace it with your own backend to secure client_secret:</span></span><span class="line"><span class="ct-f06536"> tokenEndpoint: </span><span class="ct-e50739">`https://oauth.yandex.ru/token?grant_type=authorization_code&amp;client_id=${</span><span class="ct-b47256">YANDEX_OAUTH_CLIENT</span><span class="ct-e50739">}&amp;client_secret=${</span><span class="ct-b47256">YANDEX_OAUTH_SECRET</span><span class="ct-e50739">}`</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536"> },</span></span><span class="line"><span class="ct-f06536"> clientId: </span><span class="ct-b47256">YANDEX_OAUTH_CLIENT</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536"> redirectUrl: </span><span class="ct-e50739">`${</span><span class="ct-b47256">APP_ID</span><span class="ct-e50739">}:/oauth2redirect`</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536"> scopes: [</span><span class="ct-e50739">&#39;login:info&#39;</span><span class="ct-f06536">, </span><span class="ct-e50739">&#39;login:avatar&#39;</span><span class="ct-f06536">],</span></span><span class="line"><span class="ct-f06536"> dangerouslyAllowInsecureHttpRequests: </span><span class="ct-919484">true</span><span class="ct-f06536">,</span></span><span class="line"><span class="ct-f06536">});</span></span><span class="line"></span><span class="line"><span class="ct-d5d2b2">callback</span><span class="ct-f06536">(</span><span class="ct-868453">authState</span><span class="ct-f06536">.</span><span class="ct-868453">accessToken</span><span class="ct-f06536">);</span></span></code></pre><!--]--></div><h2 id="apple-id-login"><a href="#apple-id-login"><!--[-->Apple ID login<!--]--></a></h2><p><!--[--><a href="https://github.com/invertase/react-native-apple-authentication" rel="nofollow" target="_blank"><!--[-->react-native-apple-authentication<!--]--></a> has its own <a href="https://github.com/invertase/react-native-apple-authentication/tree/main/docs" rel="nofollow" target="_blank"><!--[-->documentation<!--]--></a> on setting up OAuth using Apple ID.<!--]--></p><style>.ct-919484{color:#79C0FF}.ct-d5d2b2{color:#D2A8FF}.ct-719333{color:#8B949E}.ct-b47256{color:#79C0FF}.ct-6e5da4{color:#FF7B72}.ct-e50739{color:#A5D6FF}.ct-868453{color:#C9D1D9}.ct-f06536{color:#C9D1D9}.ct-eaff2e{color:#FF7B72}.light .ct-eaff2e{color:#859900}.light .ct-f06536{color:#657B83}.light .ct-868453{color:#268BD2}.light .ct-e50739{color:#2AA198}.light .ct-6e5da4{color:#073642}.light .ct-b47256{color:#268BD2}.light .ct-719333{color:#93A1A1}.light .ct-d5d2b2{color:#268BD2}.light .ct-919484{color:#B58900}</style></div></article><!--]--></main><!--]--><!--]--></div><footer class="_footer_ogxvf_1 _footer_vom09_18 _footer_vom09_18"><div>btw, have a nice day</div><div class="_filler_ogxvf_9"></div><div> (2018 - 2024) <a href="https://github.com/muerwre/" rel="noopener noreferrer" target="_blank">muerwre</a></div></footer></div></div></div></div></div><script type="module">import p from "/frontend/react-native/oauth2-login/_payload.js";window.__NUXT__={...p,...((function(a,b,c,d,e,f){return {state:{"$scolor-mode":{preference:b,value:b,unknown:c,forced:a}},_errors:{},serverRendered:c,config:{public:{content:{clientDB:{isSPA:a,integrity:1711020208513},navigation:{fields:[]},base:"_content",tags:{p:"prose-p",a:"prose-a",blockquote:"prose-blockquote","code-inline":"prose-code-inline",code:"prose-code",em:"prose-em",h1:"prose-h1",h2:"prose-h2",h3:"prose-h3",h4:"prose-h4",h5:"prose-h5",h6:"prose-h6",hr:"prose-hr",img:"prose-img",ul:"prose-ul",ol:"prose-ol",li:"prose-li",strong:"prose-strong",table:"prose-table",thead:"prose-thead",tbody:"prose-tbody",td:"prose-td",th:"prose-th",tr:"prose-tr"},highlight:{theme:{default:"github-dark",light:"solarized-light"},preload:[d,"c","go","graphql","scss",d,e,"docker","typescript","javascript","nginx","bash","yaml",e],apiURL:"\u002Fapi\u002F_content\u002Fhighlight"},wsUrl:f,documentDriven:a,anchorLinks:{depth:4,exclude:[1]}}},app:{baseURL:"\u002F",buildAssetsDir:"nuxt\u002F",cdnURL:f}},prerenderedAt:1711020227099}}(false,"dark",true,"shell","sh","")))}</script><script type="module" src="/nuxt/entry.0ac1105a.js" crossorigin></script><script type="module" src="/nuxt/default.5ee93473.js" crossorigin></script><script type="module" src="/nuxt/LayoutMainMenuToggle.16bf42cd.js" crossorigin></script><script type="module" src="/nuxt/LayoutMainMenu.25f8974f.js" crossorigin></script><script type="module" src="/nuxt/content.887f506f.js" crossorigin></script><script type="module" src="/nuxt/LayoutThemeToggle.c652c3fc.js" crossorigin></script><script type="module" src="/nuxt/_...slug_.848f1208.js" crossorigin></script><script type="module" src="/nuxt/LayoutFooter.b670897a.js" crossorigin></script><script type="module" src="/nuxt/ProseP.dafff666.js" crossorigin></script><script type="module" src="/nuxt/ProseH2.4b62290f.js" crossorigin></script><script type="module" src="/nuxt/ProseA.189aad8b.js" crossorigin></script><script type="module" src="/nuxt/ProseCodeInline.d05be2e8.js" crossorigin></script><script type="module" src="/nuxt/ProseH3.51f54a19.js" crossorigin></script><script type="module" src="/nuxt/ProseCode.724640cc.js" crossorigin></script><script type="module" src="/nuxt/UiIconCopy.42c3636a.js" crossorigin></script></body>
</html>