package com.example.loginbysocial.service; import com.example.loginbysocial.entity.Profile; import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseAuthException; import com.google.firebase.auth.FirebaseToken; import org.springframework.stereotype.Service; import java.io.FileInputStream; import java.io.IOException; @Service public class FirebaseService { public FirebaseToken authenticateUser(String accessToken) throws FirebaseAuthException, IOException { FileInputStream serviceAccount = new FileInputStream("./../cloud-gateway-common/loginBySocial/src/main/resources/service-account.json"); FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(GoogleCredentials.fromStream(serviceAccount)) .build(); FirebaseApp app=FirebaseApp.initializeApp(options); FirebaseAuth auth = FirebaseAuth.getInstance(app); FirebaseToken token = auth.verifyIdToken(accessToken); return token; } public Profile getInfo(FirebaseToken token){ Profile profile=new Profile(); profile.setEmail(token.getEmail()); profile.setName(token.getName()); profile.setPhoto(token.getPicture()); profile.setId(token.getUid()); return profile; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter