{"id":128069,"date":"2024-11-04T12:16:25","date_gmt":"2024-11-04T10:16:25","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=128069"},"modified":"2024-11-04T12:16:27","modified_gmt":"2024-11-04T10:16:27","slug":"firebase-authentication-spring-security-integration","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html","title":{"rendered":"Firebase Authentication-Spring Security Integration"},"content":{"rendered":"<p>Firebase Authentication is a service that allows easy user authentication with email\/password, social providers, and phone numbers. On the other hand, Spring Security is a powerful authentication and access-control framework for securing Spring-based applications. Let&#8217;s delve into understanding how Spring Security integrates with Firebase Authentication for secure and seamless user management.<\/p>\n<h2><a name=\"section-1\"><\/a>1. Introduction<\/h2>\n<h3>1.1 What is Firebase?<\/h3>\n<p><a href=\"https:\/\/firebase.google.com\/\" target=\"_blank\" rel=\"noopener\">Firebase<\/a> is a comprehensive platform developed by Google for building and managing mobile and web applications. It provides a wide range of services, including real-time databases, cloud storage, and analytics, but one of its most notable features is its robust authentication service. Firebase Authentication simplifies the process of user authentication by supporting various methods, such as email\/password, phone authentication, and popular social login providers like Google, Facebook, and Twitter. This makes it an excellent choice for modern applications requiring secure and user-friendly authentication.<\/p>\n<h3>1.2 What is Spring Security?<\/h3>\n<p><a href=\"https:\/\/spring.io\/projects\/spring-security\" target=\"_blank\" rel=\"noopener\">Spring Security<\/a> is a powerful and customizable authentication and access-control framework used in Java applications. Part of the Spring Framework ecosystem, Spring Security provides comprehensive security features to protect applications against common security threats, such as unauthorized access, CSRF attacks, and more. With support for multiple authentication methods, including OAuth2, LDAP, JWT, and custom authentication providers, Spring Security is widely used in enterprise applications to ensure robust security standards.<\/p>\n<h3>1.3 Firebase authentication with Spring security<\/h3>\n<p>Combining <a href=\"https:\/\/firebase.google.com\/docs\/auth\" target=\"_blank\" rel=\"noopener\">Firebase Authentication<\/a> with Spring Security allows developers to create secure applications that leverage Firebase&#8217;s authentication capabilities while benefiting from Spring Security&#8217;s extensive authorization and security features. By integrating Firebase with Spring Security, developers can manage user authentication seamlessly, implement role-based access control, and protect sensitive resources effectively in their applications.<\/p>\n<h2><a name=\"section-2\"><\/a>2. Setting up the Project<\/h2>\n<p>We\u2019ll start by creating a Spring Boot project with the necessary dependencies. In the <code>pom.xml<\/code> file, add the following dependencies:<\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-security&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;com.google.firebase&lt;\/groupId&gt;\n    &lt;artifactId&gt;firebase-admin&lt;\/artifactId&gt;\n    &lt;version&gt;8.0.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n<\/pre>\n<h2><a name=\"section-3\"><\/a>3. Generating the authentication file in Firebase?<\/h2>\n<ul>\n<li>Go to the Firebase Console: Visit <a href=\"https:\/\/console.firebase.google.com\/\" target=\"_blank\" rel=\"noopener\">https:\/\/console.firebase.google.com\/<\/a> and sign in with your Google account.<\/li>\n<li>Select Your Project: If you already have a Firebase project, select it from the dashboard. If not, create a new project by clicking &#8220;Add Project&#8221; and following the setup steps.<\/li>\n<li>Open Project Settings: In your Firebase project dashboard, click on the gear icon next to &#8220;Project Overview&#8221; in the top-left corner. Select <code>Project settings<\/code> from the dropdown menu.<\/li>\n<li>Go to the Service Accounts Tab: In the Project Settings page, navigate to the <code>Service accounts<\/code> tab. This tab contains information and options for setting up Firebase Admin SDK for server-side code.<\/li>\n<li>Generate a New Private Key: Under the &#8220;Firebase Admin SDK&#8221; section, you\u2019ll see a button labeled <code>Generate new private key<\/code>. Click this button.<\/li>\n<li>Confirm Key Creation: A dialog box will appear asking if you want to generate a new private key. Click <code>Generate<\/code> to proceed. This will download the <code>serviceAccountKey.json<\/code> file to your computer.<\/li>\n<li>Save the File Securely: Place the <code>serviceAccountKey.json<\/code> file in a secure location within your project directory. Avoid committing this file to source control (e.g., Git) as it contains sensitive information.<\/li>\n<\/ul>\n<h2><a name=\"section-4\"><\/a>4. Creating Users in Firebase Authentication<\/h2>\n<p>Firebase allows you to create and manage users through its console or programmatically.<\/p>\n<h3>4.1 Creating a configuration class<\/h3>\n<p>First, initialize Firebase by adding a configuration class that loads your service account JSON key file:<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\nimport com.google.auth.oauth2.GoogleCredentials;\nimport com.google.firebase.FirebaseApp;\nimport com.google.firebase.FirebaseOptions;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\n\nimport java.io.FileInputStream;\nimport java.io.IOException;\n\n@Configuration\npublic class FirebaseConfig {\n    @Bean\n    public FirebaseApp initializeFirebase() throws IOException {\n        FileInputStream serviceAccount = new FileInputStream(\"path\/to\/your\/serviceAccountKey.json\");\n        FirebaseOptions options = FirebaseOptions.builder()\n                .setCredentials(GoogleCredentials.fromStream(serviceAccount))\n                .build();\n        return FirebaseApp.initializeApp(options);\n    }\n}\n<\/pre>\n<h4>4.1.1 Code Explanation<\/h4>\n<p>This code defines a configuration class in a Spring Boot application to initialize and configure Firebase. The class is annotated with <code>@Configuration<\/code>, indicating that it is a Spring configuration class. This allows it to define beans and configurations to be managed within the Spring application context. <\/p>\n<p>Inside the <code>FirebaseConfig<\/code> class, a method <code>initializeFirebase<\/code> is defined, annotated with <code>@Bean<\/code>. The <code>@Bean<\/code> annotation instructs Spring to manage the returned object from this method as a bean, making it available for dependency injection throughout the application. The <code>initializeFirebase<\/code> method is responsible for setting up the Firebase application instance with necessary configurations.<\/p>\n<p>Within the <code>initializeFirebase<\/code> method, a <code>FileInputStream<\/code> is used to read the Firebase service account key file, specified by <code>\"path\/to\/your\/serviceAccountKey.json\"<\/code>. This JSON file contains credentials required to authenticate with Firebase, so it must be replaced with the actual path to your Firebase service account key.<\/p>\n<p>After opening the service account file, a <code>FirebaseOptions<\/code> object is created using a builder pattern. The <code>setCredentials<\/code> method is called on this builder, where the service account credentials are loaded and passed. This sets up the authentication for Firebase, enabling it to perform server-side operations securely.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Finally, the method calls <code>FirebaseApp.initializeApp(options)<\/code>, which initializes the Firebase application with the specified options. This <code>FirebaseApp<\/code> instance is returned from the method, allowing it to be injected wherever needed in the application for Firebase services.<\/p>\n<h3>4.2 Creating new users<\/h3>\n<p>Once Firebase is initialized, we can create new users:<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\nimport com.google.firebase.auth.FirebaseAuth;\nimport com.google.firebase.auth.UserRecord;\nimport org.springframework.stereotype.Service;\n\n@Service\npublic class FirebaseUserService {\n    public UserRecord createUser(String email, String password) throws Exception {\n        UserRecord.CreateRequest request = new UserRecord.CreateRequest()\n                .setEmail(email)\n                .setPassword(password);\n        return FirebaseAuth.getInstance().createUser(request);\n    }\n}\n<\/pre>\n<h4>4.2.1 Code Explanation<\/h4>\n<p>This code defines a Spring service class called <code>FirebaseUserService<\/code> that provides functionality for creating a new user in Firebase Authentication. The class is annotated with <code>@Service<\/code>, which designates it as a service component in the Spring application. This allows Spring to manage it as a singleton bean, making it accessible for dependency injection throughout the application.<\/p>\n<p>The main functionality of this class is provided by the <code>createUser<\/code> method, which takes two parameters: <code>email<\/code> and <code>password<\/code>. These parameters represent the email and password of the user that will be created in Firebase. The method is declared to throw an <code>Exception<\/code> to handle any potential errors that might occur while interacting with Firebase.<\/p>\n<p>Within the <code>createUser<\/code> method, an instance of <code>UserRecord.CreateRequest<\/code> is created and configured with the provided email and password. This is done using a builder-style method where <code>setEmail<\/code> and <code>setPassword<\/code> are called on the <code>CreateRequest<\/code> object. This configuration prepares a request object that specifies the details of the user to be created.<\/p>\n<p>Next, the <code>FirebaseAuth.getInstance().createUser(request)<\/code> method is called. <code>FirebaseAuth.getInstance()<\/code> retrieves the Firebase Authentication instance, and <code>createUser<\/code> sends the request to Firebase to create the new user. If successful, this method returns a <code>UserRecord<\/code> object representing the newly created user.<\/p>\n<h2><a name=\"section-5\"><\/a>5. Implementing User Login Functionality<\/h2>\n<p>Firebase provides a token upon successful login that we can validate on the backend. <\/p>\n<p>Here\u2019s how the client-side login might look in JavaScript:<\/p>\n<pre class=\"brush:js; wrap-lines:false;\">\nfirebase.auth().signInWithEmailAndPassword(email, password)\n    .then((userCredential) =&gt; {\n        userCredential.user.getIdToken().then((idToken) =&gt; {\n            \/\/ Send idToken to the backend\n        });\n    })\n    .catch((error) =&gt; {\n        console.error(\"Error signing in:\", error);\n    });\n<\/pre>\n<h3>5.1 Code Explanation<\/h3>\n<p>This code demonstrates how to use Firebase Authentication to sign in a user with an email and password. The method <code>firebase.auth().signInWithEmailAndPassword(email, password)<\/code> is called, where <code>email<\/code> and <code>password<\/code> are the credentials provided by the user for authentication. This method initiates the sign-in process and returns a promise, which either resolves with a <code>userCredential<\/code> object on successful login or rejects with an error if authentication fails.<\/p>\n<p>Upon successful login, the <code>then<\/code> method is executed, where a <code>userCredential<\/code> object is passed to the callback function. The <code>userCredential<\/code> object contains information about the authenticated user, including the user\u2019s ID token. Within this callback, <code>userCredential.user.getIdToken()<\/code> is called, which retrieves the ID token for the signed-in user. This ID token is essential for backend authentication, as it verifies the user\u2019s identity.<\/p>\n<p>The ID token is then available in another promise that resolves with the <code>idToken<\/code> variable. Typically, this <code>idToken<\/code> would be sent to the backend server (e.g., through an HTTP request) to allow the server to verify the user&#8217;s identity and grant access to protected resources.<\/p>\n<p>If there is an error during the sign-in process, the <code>catch<\/code> method is triggered, which handles any errors that may occur, such as invalid credentials or network issues. In this example, the error is logged to the console using <code>console.error<\/code> to help identify the issue.<\/p>\n<h2><a name=\"section-6\"><\/a>6. Exchanging Refresh Tokens for New ID Tokens<\/h2>\n<p>ID tokens from Firebase expire periodically, so it\u2019s essential to handle token renewal on the client side. Firebase provides a refresh token mechanism to help you get a new ID token without re-authenticating.<\/p>\n<pre class=\"brush:js; wrap-lines:false;\">\nfirebase.auth().currentUser.getIdToken(true).then((idToken) =&gt; {\n    \/\/ Use the new ID token\n}).catch((error) =&gt; {\n    console.error(\"Error refreshing token:\", error);\n});\n<\/pre>\n<h3>6.1 Code Explanation<\/h3>\n<p>This code snippet demonstrates how to refresh a user\u2019s Firebase ID token to ensure they have a valid authentication token. Firebase ID tokens have a limited lifespan, so refreshing the token periodically is necessary for continued authentication in applications with long-lived sessions.<\/p>\n<p>The code begins with <code>firebase.auth().currentUser.getIdToken(true)<\/code>, which attempts to retrieve a fresh ID token for the currently signed-in user. The <code>getIdToken<\/code> method accepts a boolean parameter. Passing <code>true<\/code> forces the refresh of the ID token, ensuring that the application receives a new and valid token even if the previous one is still valid but close to expiration.<\/p>\n<p>This method returns a promise that resolves with the refreshed ID token, represented by the <code>idToken<\/code> variable in the <code>then<\/code> callback function. The refreshed <code>idToken<\/code> can be used as the new authentication token to securely communicate with the backend or access protected resources, providing proof of the user\u2019s identity and keeping the session active.<\/p>\n<p>If there is an error during the token refresh process, the <code>catch<\/code> block is executed. In this example, the <code>catch<\/code> method logs any errors to the console using <code>console.error<\/code>, which helps to identify and debug issues related to token refreshing, such as network problems or expired sessions.<\/p>\n<h2><a name=\"section-7\"><\/a>7. Integrating With Spring Security<\/h2>\n<p>Next, we\u2019ll add a filter to validate Firebase ID tokens with each request. This filter will extract the token from the Authorization header, validate it with Firebase, and then set the authenticated user in the Spring Security context.<\/p>\n<h3>7.1 Firebase Authentication Filter<\/h3>\n<p>Create a filter class, <code>FirebaseAuthenticationFilter<\/code>:<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\nimport com.google.firebase.auth.FirebaseAuth;\nimport com.google.firebase.auth.FirebaseToken;\nimport org.springframework.security.authentication.UsernamePasswordAuthenticationToken;\nimport org.springframework.security.core.context.SecurityContextHolder;\nimport org.springframework.security.web.authentication.WebAuthenticationDetailsSource;\n\nimport javax.servlet.FilterChain;\nimport javax.servlet.Filter;\nimport javax.servlet.FilterConfig;\nimport javax.servlet.ServletException;\nimport javax.servlet.ServletRequest;\nimport javax.servlet.ServletResponse;\nimport java.io.IOException;\n\npublic class FirebaseAuthenticationFilter implements Filter {\n    @Override\n    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)\n            throws IOException, ServletException {\n        String token = getBearerTokenFromRequest(request);\n\n        if (token != null) {\n            FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdToken(token);\n            UsernamePasswordAuthenticationToken authentication = \n                new UsernamePasswordAuthenticationToken(decodedToken.getUid(), null, Collections.emptyList());\n            authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));\n            SecurityContextHolder.getContext().setAuthentication(authentication);\n        }\n        \n        chain.doFilter(request, response);\n    }\n\n    private String getBearerTokenFromRequest(ServletRequest request) {\n        String authorization = ((HttpServletRequest) request).getHeader(\"Authorization\");\n        if (authorization != null &amp;&amp; authorization.startsWith(\"Bearer \")) {\n            return authorization.substring(7);\n        }\n        return null;\n    }\n}\n<\/pre>\n<h4>7.1.1 Code Explanation<\/h4>\n<p>This code defines a custom filter, <code>FirebaseAuthenticationFilter<\/code>, which is implemented to integrate Firebase Authentication with Spring Security. The purpose of this filter is to intercept incoming HTTP requests, extract and verify Firebase authentication tokens, and then set the authenticated user in the Spring Security context if the token is valid. This filter class implements the <code>Filter<\/code> interface, allowing it to be registered in the Spring Security filter chain.<\/p>\n<p>The main functionality is in the <code>doFilter<\/code> method, which is overridden from the <code>Filter<\/code> interface. This method intercepts each HTTP request and processes it before it reaches other parts of the application. Inside <code>doFilter<\/code>, the <code>getBearerTokenFromRequest<\/code> method is called to extract the bearer token from the HTTP request&#8217;s Authorization header. If the Authorization header contains a token starting with &#8220;Bearer &#8220;, this method retrieves the token part by removing the &#8220;Bearer &#8221; prefix; otherwise, it returns <code>null<\/code>.<\/p>\n<p>If a valid token is present, the code proceeds to verify it with Firebase. <code>FirebaseAuth.getInstance().verifyIdToken(token)<\/code> verifies the extracted token with Firebase, returning a <code>FirebaseToken<\/code> object if the token is valid. The <code>FirebaseToken<\/code> object contains authenticated user information, including the user&#8217;s unique ID (UID).<\/p>\n<p>Next, a <code>UsernamePasswordAuthenticationToken<\/code> object is created to represent the authenticated user within Spring Security. The UID from the <code>FirebaseToken<\/code> is used as the principal (the unique user identifier), and <code>null<\/code> is set for credentials as password verification is managed by Firebase. An empty list of authorities is provided, but you could customize this to include specific user roles if needed. Additionally, <code>authentication.setDetails<\/code> is called to set request-specific details, such as the remote address, using a <code>WebAuthenticationDetailsSource<\/code> object.<\/p>\n<p>Once the <code>UsernamePasswordAuthenticationToken<\/code> is created, it is set in the <code>SecurityContextHolder<\/code>, which stores the authentication information in the current security context. This allows Spring Security to recognize the user as authenticated and grants access to secured resources based on their session.<\/p>\n<p>Finally, the filter chain continues by calling <code>chain.doFilter(request, response)<\/code>, passing the request and response to the next filter or servlet in the chain. If the token is invalid or missing, the filter simply passes the request through without setting an authenticated user in the security context.<\/p>\n<h3>7.2 Configuring Spring Security<\/h3>\n<p>Finally, integrate the filter into Spring Security\u2019s configuration by creating a <code>SecurityConfig<\/code> class:<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.security.config.annotation.web.builders.HttpSecurity;\nimport org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;\nimport org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;\n\n@Configuration\n@EnableWebSecurity\npublic class SecurityConfig extends WebSecurityConfigurerAdapter {\n\n    @Override\n    protected void configure(HttpSecurity http) throws Exception {\n        http\n            .csrf().disable()\n            .authorizeRequests()\n            .anyRequest().authenticated()\n            .and()\n            .addFilterBefore(new FirebaseAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);\n    }\n}\n<\/pre>\n<h4>7.2.1 Code Explanation<\/h4>\n<p>This code defines a Spring Security configuration class, <code>SecurityConfig<\/code>, that extends <code>WebSecurityConfigurerAdapter<\/code>. This class is responsible for configuring security settings in the Spring Boot application, particularly to integrate Firebase Authentication with Spring Security.<\/p>\n<p>The class is annotated with <code>@Configuration<\/code> and <code>@EnableWebSecurity<\/code>. The <code>@Configuration<\/code> annotation designates this class as a configuration class, enabling it to define and manage beans for the Spring application context. The <code>@EnableWebSecurity<\/code> annotation enables Spring Security\u2019s web security support, allowing custom security configurations to be applied to HTTP requests.<\/p>\n<p>The main security configuration is defined in the overridden <code>configure<\/code> method, which accepts an <code>HttpSecurity<\/code> object. This method customizes the security settings for HTTP requests in the application. Here, several configurations are applied to manage authentication and the security filter chain:<\/p>\n<p>First, <code>csrf().disable()<\/code> disables CSRF (Cross-Site Request Forgery) protection for simplicity. CSRF protection is often disabled in APIs and mobile applications where the server and client are separate and the frontend handles authentication securely. However, enabling CSRF is recommended for web applications where CSRF attacks are a risk.<\/p>\n<p>Next, <code>authorizeRequests().anyRequest().authenticated()<\/code> configures authorization for all incoming HTTP requests. The <code>anyRequest().authenticated()<\/code> directive ensures that every request requires authentication. This means that only authenticated users can access any endpoint in the application, helping protect sensitive resources from unauthorized access.<\/p>\n<p>Finally, the <code>addFilterBefore<\/code> method is used to add a custom filter, <code>FirebaseAuthenticationFilter<\/code>, into the security filter chain. This filter is inserted before <code>UsernamePasswordAuthenticationFilter<\/code>, ensuring that Firebase token verification occurs early in the filter chain. By verifying the Firebase token, <code>FirebaseAuthenticationFilter<\/code> sets up the Spring Security context with the authenticated user, allowing Spring Security to control access based on the verified identity.<\/p>\n<h2><a name=\"section-8\"><\/a>8. Run the code<\/h2>\n<p>Execute the following command to run the application and it should be running locally on the following endpoint \u2013 <code>http:\/\/localhost:8080<\/code>.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">\nmvn spring-boot:run\n<\/pre>\n<p>Use the frontend call to authenticate the users and obtain an ID token from the Firebase. Once done include the token in the Authorization header to further play with the application.<\/p>\n<h2><a name=\"section-9\"><\/a>9. Conclusion<\/h2>\n<p>In this guide, we integrated Firebase Authentication with Spring Security in a Spring Boot application. By using Firebase tokens, we were able to authenticate users and secure requests effectively. This setup provides a robust, scalable authentication solution that takes advantage of Firebase\u2019s identity management capabilities and Spring Security\u2019s access control.<\/p>\n<p>Further improvements could include role-based access control, additional security configurations, and error handling for token validation failures. With this foundation, your application is now ready to securely manage user authentication using Firebase and Spring Security.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Firebase Authentication is a service that allows easy user authentication with email\/password, social providers, and phone numbers. On the other hand, Spring Security is a powerful authentication and access-control framework for securing Spring-based applications. Let&#8217;s delve into understanding how Spring Security integrates with Firebase Authentication for secure and seamless user management. 1. Introduction 1.1 What &hellip;<\/p>\n","protected":false},"author":26931,"featured_media":242,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[1387,125],"class_list":["post-128069","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-firebase","tag-spring-security"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Firebase Authentication-Spring Security Integration - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Spring security Firebase authentication: Securely integrate Firebase Authentication with Spring Security for user management in Java apps.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Firebase Authentication-Spring Security Integration - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Spring security Firebase authentication: Securely integrate Firebase Authentication with Spring Security for user management in Java apps.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-04T10:16:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-04T10:16:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin Batra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin Batra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html\"},\"author\":{\"name\":\"Yatin Batra\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\"},\"headline\":\"Firebase Authentication-Spring Security Integration\",\"datePublished\":\"2024-11-04T10:16:25+00:00\",\"dateModified\":\"2024-11-04T10:16:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html\"},\"wordCount\":2207,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-security-logo.jpg\",\"keywords\":[\"Firebase\",\"Spring Security\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html\",\"name\":\"Firebase Authentication-Spring Security Integration - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-security-logo.jpg\",\"datePublished\":\"2024-11-04T10:16:25+00:00\",\"dateModified\":\"2024-11-04T10:16:27+00:00\",\"description\":\"Spring security Firebase authentication: Securely integrate Firebase Authentication with Spring Security for user management in Java apps.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-security-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-security-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/firebase-authentication-spring-security-integration.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Firebase Authentication-Spring Security Integration\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\",\"name\":\"Yatin Batra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"caption\":\"Yatin Batra\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\\\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/yatin-batra\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Firebase Authentication-Spring Security Integration - Java Code Geeks","description":"Spring security Firebase authentication: Securely integrate Firebase Authentication with Spring Security for user management in Java apps.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html","og_locale":"en_US","og_type":"article","og_title":"Firebase Authentication-Spring Security Integration - Java Code Geeks","og_description":"Spring security Firebase authentication: Securely integrate Firebase Authentication with Spring Security for user management in Java apps.","og_url":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2024-11-04T10:16:25+00:00","article_modified_time":"2024-11-04T10:16:27+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","type":"image\/jpeg"}],"author":"Yatin Batra","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin Batra","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html"},"author":{"name":"Yatin Batra","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d"},"headline":"Firebase Authentication-Spring Security Integration","datePublished":"2024-11-04T10:16:25+00:00","dateModified":"2024-11-04T10:16:27+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html"},"wordCount":2207,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","keywords":["Firebase","Spring Security"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html","url":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html","name":"Firebase Authentication-Spring Security Integration - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","datePublished":"2024-11-04T10:16:25+00:00","dateModified":"2024-11-04T10:16:27+00:00","description":"Spring security Firebase authentication: Securely integrate Firebase Authentication with Spring Security for user management in Java apps.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-security-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/firebase-authentication-spring-security-integration.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Firebase Authentication-Spring Security Integration"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d","name":"Yatin Batra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","caption":"Yatin Batra"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/yatin-batra"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/128069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/26931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=128069"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/128069\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/242"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=128069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=128069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=128069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}