Skip to content

AgeOfMobile/spring-firebase-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This small library helps you integrating Firebase Auth into your Spring Boot application. It will parse ID Token (JWT) from the Authorization header, verify it then provides a FirebaseUser instance for the current request.

To use it, you need to add following snippet into your build.gradle file:

repositories {
...
	maven {
		url 'https://dl.bintray.com/ageofmobile/spring-firebase-auth'
	}
...	
}

dependencies {
...
	compile('com.ageofmobile:spring-firebase-auth:0.0.4')
...
}

Add @EnableFirebaseSecurity to your Spring Boot Application class:

@SpringBootApplication
@EnableResourceServer
@EnableFirebaseSecurity
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

Create a configuration class, extend from FirebaseResourceServerConfig class to configure your authentication/authorization rules:

@Configuration
public class ResourceServerConfig extends FirebaseResourceServerConfig {
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().authenticated();
    }
}

In your resourses/application.yaml (or application.properties) you need to add following configuration:

security.oauth2.resource.id: 'your-firebase-app-id'

In your controller classes, you can get the current user by adding a FirebaseUser parameter to request methods:

@RestController
public class ContentControler {
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public @ResponseBody String sayHello(FirebaseUser user) {
        return "Hello " + user.getName();
    }
}

About

Spring Security + Firebase Auth

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages