{"id":19069249,"url":"https://github.com/msukmanowsky/gapi-firebase","last_synced_at":"2025-04-28T14:10:32.249Z","repository":{"id":139814458,"uuid":"119478569","full_name":"msukmanowsky/gapi-firebase","owner":"msukmanowsky","description":"An example of how to use GAPI and Firebase Auth together to authenticate users and talk to Google APIs.","archived":false,"fork":false,"pushed_at":"2022-06-09T16:50:48.000Z","size":6,"stargazers_count":53,"open_issues_count":3,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T16:29:19.652Z","etag":null,"topics":["firebase","firebase-auth","google-api","google-api-client"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msukmanowsky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-30T03:44:15.000Z","updated_at":"2024-11-11T19:04:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f46f788-33e9-49b5-a661-5c1bedc39c24","html_url":"https://github.com/msukmanowsky/gapi-firebase","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msukmanowsky%2Fgapi-firebase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msukmanowsky%2Fgapi-firebase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msukmanowsky%2Fgapi-firebase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msukmanowsky%2Fgapi-firebase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msukmanowsky","download_url":"https://codeload.github.com/msukmanowsky/gapi-firebase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251326849,"owners_count":21571636,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebase","firebase-auth","google-api","google-api-client"],"created_at":"2024-11-09T01:13:48.295Z","updated_at":"2025-04-28T14:10:32.221Z","avatar_url":"https://github.com/msukmanowsky.png","language":"HTML","readme":"# GAPI and Firebase Auth\n\nAn example of how to use GAPI and Firebase Auth together to authenticate users\nand talk to Google APIs.\n\n## Background\n\nIf you are trying to use [Google's JavaScript Library](https://developers.google.com/api-client-library/javascript/)\nto query Google APIs (e.g. Google Analytics), you'll run into an issue whereby\nFirebase Auth is strictly intended for AuthN (fetching a user's identity and\nnot AuthZ (authorizing a user to access specific resources).\n\nThe access token that Firebase Auth provides _is valid_ for whatever scopes\na user approved, but Firebase Auth does not provide any means to see the\naccess token upon, say, token refreshes. This is\n[by design](https://github.com/firebase/firebaseui-web/issues/294).\n\nGoogle's JavaScript Library transparently handles token refreshes but\nwill also provide access to the updated token via:\n\n```javascript\nconst auth2 = gapi.auth2.getAuthInstance()\nauth2.isSignedIn.listen(isSignedIn =\u003e {\n  if (isSignedIn) {\n    const currentUser = auth2.currentUser.get()\n    const authResponse = currentUser.getAuthResponse(true)\n    authResponse.id_token\n    authResponse.access_token\n  }\n})\n```\n\nThese same credentials can also be used to authorize a user to Firebase!\n\n```javascript\nconst credential = firebase.auth.GoogleAuthProvider.credential(\n  authResponse.id_token,\n  authResponse.access_token\n)\nfirebase.auth().signInWithCredential(credential)\n```\n\nThere are some additional concerns to keep in mind like signing out of both\n`gapi` and `firebase`:\n\n```javascript\nconst auth2 = gapi.auth2.getAuthInstance()\nauth2.signOut()\n  .then(() =\u003e { return firebase.auth().signOut() })\n```\n\nNow you have the best of both worlds, the ability to make requests to any\nGoogle API via `gapi` and an authenticated `firebase` client to communicate\nwith firebase APIs.\n\n## Running this example:\n\n1. Clone this repo locally.\n1. [Sign up](https://firebase.google.com) for a Firebase app.\n1. [Enable](https://console.cloud.google.com/apis/dashboard) the \"Analytics\nAPI\" for Firebase project.\n1. Find the [OAuth Client ID](https://console.cloud.google.com/apis/credentials)\nfirebase auto-created on setup and ensure your server's origin is listed in\n\"Authorised JavaScript origins\" (should be something like\n  `http://localhost:8000`, but depends on your server config).\n1. Search the source code for `//OVERWRITE ME` and fill in your relevant\nconfiguration.\n1. Run your webserver (Python's `SimpleHTTPServer` is a\ngreat choice) and open the page.\n1. Open up your browser's dev console and check logging messages.\n1. Click login!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsukmanowsky%2Fgapi-firebase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsukmanowsky%2Fgapi-firebase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsukmanowsky%2Fgapi-firebase/lists"}