{"id":22515275,"url":"https://github.com/iethem/spring-jwt-firebase","last_synced_at":"2025-08-03T16:31:34.258Z","repository":{"id":42866900,"uuid":"259025747","full_name":"iethem/spring-jwt-firebase","owner":"iethem","description":"Spring Boot JWT Example with Firebase Authentication","archived":false,"fork":false,"pushed_at":"2022-12-10T08:57:25.000Z","size":2433,"stargazers_count":21,"open_issues_count":6,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-07T17:50:53.418Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iethem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-26T12:32:48.000Z","updated_at":"2023-01-31T18:07:25.000Z","dependencies_parsed_at":"2023-01-26T00:31:20.083Z","dependency_job_id":null,"html_url":"https://github.com/iethem/spring-jwt-firebase","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iethem%2Fspring-jwt-firebase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iethem%2Fspring-jwt-firebase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iethem%2Fspring-jwt-firebase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iethem%2Fspring-jwt-firebase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iethem","download_url":"https://codeload.github.com/iethem/spring-jwt-firebase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228556465,"owners_count":17936433,"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":[],"created_at":"2024-12-07T03:29:07.737Z","updated_at":"2024-12-07T03:29:08.335Z","avatar_url":"https://github.com/iethem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring Boot JWT Example with Firebase Authentication\nSpring Security OAuth2 implementation to make use of JSON Web Tokens\n\u003e [Do it yourself!](DIY.md)\n\n- Firebase Authentication\n- Cloud Firestore\n- React\n- Spring Boot\n- Spring Security\n\n## Project Structure\n```\nsrc\n└── main\n    ├── docker \n    ├── java\n    ├── javascript\n    └── resources\n```\n\n## Usage\n1. Create a Firebase Application on Firebase ([more information](https://gitlab.eteration.com/blogs/www/blob/master/2019/October/Firebase.md#creating-a-firebase-application))\n    - Activate Sign-in Providers: Email/Password and Google.\n    - Create Database (Cloud Firestore)\n2. Create a web app on your Firebase Project Settings\n    - Replace your config with `src/main/javascript/app/firebaseConfig.js`\n    ```js\n    const firebaseConfig = {\n        apiKey: '\u003cyour-apiKey\u003e',\n        authDomain: '\u003cyour-authDomain\u003e',\n        databaseURL: '\u003cyour-databaseURL\u003e',\n        projectId: '\u003cyour-projectId\u003e',\n        storageBucket: '\u003cyour-storageBucket\u003e',\n        messagingSenderId: '\u003cyour-messagingSenderId\u003e',\n        appId: '\u003cyour-appId\u003e',\n    };\n\n    export default firebaseConfig;\n    ```\n3. Create a service account for Java on your Firebase Project Settings\n    - Replace your config with `src/main/resources/firebase-service-credentials.json`\n    ```json\n    {\n        \"type\": \"\u003cyour-type\u003e\",\n        \"project_id\": \"\u003cyour-project_id\u003e\",\n        \"private_key_id\": \"\u003cyour-private_key_id\u003e\",\n        \"private_key\": \"\u003cyour-private_key\u003e\",\n        \"client_email\": \"\u003cyour-client_email\u003e\",\n        \"client_id\": \"\u003cyour-client_id\u003e\",\n        \"auth_uri\": \"\u003cyour-auth_uri\u003e\",\n        \"token_uri\": \"\u003cyour-token_uri\u003e\",\n        \"auth_provider_x509_cert_url\": \"\u003cyour-auth_provider_x509_cert_url\u003e\",\n        \"client_x509_cert_url\": \"\u003cyour-client_x509_cert_url\u003e\"\n    }\n    ```\n4. Replace your `project id` on `src/main/resources/application.yml`\n\t```\n\tspring:\n\t  security:\n\t    oauth2:\n\t      resourceserver:\n\t\tjwt:\n\t\t  issuer-uri: https://securetoken.google.com/\u003cproject-id\u003e          \t\t\t   \n\t\t  jwk-set-uri: https://www.googleapis.com/robot/v1/metadata/jwk/securetoken@system.gserviceaccount.com\n\t```\n\n## React\nOpen the project from CLI and run the following commands:\n\n    cd src/main/javascript\n    npm i\n    npm start\n    \n\u003e Other npm scripts can be found on [react-boilerplate/commands](https://github.com/react-boilerplate/react-boilerplate/blob/master/docs/general/commands.md#command-line-commands)\n\nTo use other sign-in providers like Facebook, Twitter:\n- Add providers on Firebase\n- Configure the Firebase UI config\n\n```js\n//../javascript/app/containers/HomePage/index.js\n\nconst uiConfig = {\n  // Popup signin flow rather than redirect flow.\n  signInFlow: 'popup',\n  // We will display Email and Google as auth providers.\n  signInOptions: [\n    firebase.auth.EmailAuthProvider.PROVIDER_ID,\n    firebase.auth.GoogleAuthProvider.PROVIDER_ID,\n  ],\n  callbacks: {\n    // Avoid redirects after sign-in.\n    signInSuccessWithAuthResult: () =\u003e false,\n  },\n};\n```\n\u003e Learn more configuring sign-in providers on [firebaseui-web](https://github.com/firebase/firebaseui-web/#configuring-sign-in-providers).\n\n## Spring Boot\n\nOpen the project from CLI and run the following commands:\n\n    ./gradlew bootRun\n\n## Building\n\n**Note:** If you have added new routes on React application check `MvcConfig.java` under the `src/main/java` folder.\n\nTo install npm packages: \n\u003e If you installed packages you don't need to run this command\n\n    ./gradlew npmInstall\n\nTo build react app:\n    \n    ./gradlew npmBuild\n\nTo copy build output to src/main/resources/web:\n    \n    ./gradlew copyNewBuild\n\nTo build Java app:\n\n    ./gradlew build\n\nTo create docker image for the whole application:\n\n    ./gradlew docker \n\nOnce the build has finished, you can start the application via the command-line. Go to `build/libs` folder and execute the jar file:\n\n    java -jar firebase-0.0.1-SNAPSHOT.jar\n\nPoint your browser to it and you should see the newly created React app running.\n\n    http://localhost:8080\n\nTo dockerize the application:\n\n    ./gradlew docker\n\nTo run docker image:\n\n    docker run --rm -it -p 8080:8080 iethem/firebase\n\n## Retrieving/Validating ID tokens\n\u003e Use the React application to get ID tokens, the Spring Boot application does not provide ID tokens.\n\nWhen a user or device successfully signs in, Firebase creates a corresponding ID token that uniquely identifies them and grants them access to several resources, such as Firebase Realtime Database and Cloud Storage. We can re-use that ID token to identify the user or device on our custom backend server. To retrieve the ID token from the client (React), make sure the user is signed in and then get the ID token from the signed-in user:\n```js\nfirebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {\n  console.log(idToken)\n  // Send token to your backend via HTTPS\n  // ...\n}).catch(function(error) {\n  // Handle error\n});\n\n// Check src/main/javascript/app/utils/request.js\n```\n\nOnce we have an ID token, we can send that JWT to our backend and validate it:\n```command\ncurl http://localhost:8080/api/user\n\t-H \"Accept: application/json\"\n\t-H \"Authorization: Bearer {idToken}\"\n```\n\n## Reference\nYou can find a related post for this repository [here](https://gitlab.eteration.com/blogs/www/blob/master/2019/October/Firebase.md). \n\n## License\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiethem%2Fspring-jwt-firebase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiethem%2Fspring-jwt-firebase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiethem%2Fspring-jwt-firebase/lists"}