firebase-admin-java icon indicating copy to clipboard operation
firebase-admin-java copied to clipboard

Unknown error while making a remote service call: Unexpected error refreshing access token

Open bawantha opened this issue 3 years ago • 1 comments

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Windows 10
  • Firebase SDK version: 8.1.0
  • Library version: _____
  • Firebase Product: auth

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I wanted to get registered users of FIrebase to my Spring application so I initialized firebase app as shown here

@Service
@Slf4j
public class MSFirebaseInitializer
{
	@Value("${FIREBASE_SERVICE_CONFIG_KEY}")
	private String firebaseConfigPath;

	@SneakyThrows
	@PostConstruct
	public void initialize() throws IOException
	{
		try
		{

			FirebaseOptions options = new FirebaseOptions.Builder()
					.setCredentials( GoogleCredentials.fromStream( new FileInputStream( firebaseConfigPath ) ) )
					.build();
			if ( FirebaseApp.getApps().isEmpty() )
			{
				FirebaseApp.initializeApp( options );
				log.info( "Firebase application has been initialized" );
			}
		}
		catch ( IOException e )
		{
			log.error( e.getMessage() );
		}
	}
}

I wrote two tests as down bellow

@RunWith(SpringRunner.class)
@SpringBootTest
public class MSFirebaseTest
{
	@Autowired
	MSFirebaseInitializer firebaseInitializer;

	@Test
	public void firebaseAppInitializationTest() throws IOException, FirebaseAuthException
	{
		firebaseInitializer.initialize();
		System.out.println(FirebaseApp.getApps());
		assertFalse(FirebaseApp.getApps().isEmpty());
	}

		@Test
		public  void connect_dev(){
			UserRecord userRecord = null;
			try
			{
				userRecord= FirebaseAuth.getInstance(FirebaseApp.getInstance()).getUserByPhoneNumber( "+9xxx" );
			}
			catch ( FirebaseAuthException e)
			{
				e.printStackTrace();
			}

			assertEquals( userRecord.getPhoneNumber(),"+9xxx" );


		}
//
}

First test get pass and in the second test I'm getting AuthException

com.google.firebase.auth.FirebaseAuthException: Unknown error while making a remote service call: Unexpected error refreshing access token
	at com.google.firebase.auth.internal.AuthErrorHandler.createException(AuthErrorHandler.java:122)
	at com.google.firebase.auth.internal.AuthErrorHandler.createException(AuthErrorHandler.java:35)
	at com.google.firebase.internal.AbstractHttpErrorHandler.handleIOException(AbstractHttpErrorHandler.java:63)
	at com.google.firebase.internal.ErrorHandlingHttpClient.createHttpRequest(ErrorHandlingHttpClient.java:141)
	at com.google.firebase.internal.ErrorHandlingHttpClient.send(ErrorHandlingHttpClient.java:92)
	at com.google.firebase.auth.internal.AuthHttpClient.sendRequest(AuthHttpClient.java:75)
	at com.google.firebase.auth.FirebaseUserManager.lookupUserAccount(FirebaseUserManager.java:238)
	at com.google.firebase.auth.FirebaseUserManager.getUserByPhoneNumber(FirebaseUserManager.java:133)
	at com.google.firebase.auth.AbstractFirebaseAuth$8.execute(AbstractFirebaseAuth.java:557)
	at com.google.firebase.auth.AbstractFirebaseAuth$8.execute(AbstractFirebaseAuth.java:554)
	at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36)
	at com.google.firebase.auth.AbstractFirebaseAuth.getUserByPhoneNumber(AbstractFirebaseAuth.java:534)

Can anyone help me. What I'm doing wrong?

P.S. I got ErrorCode as UNKNOWN

bawantha avatar Jan 18 '22 06:01 bawantha

Hi @bawantha do you still have this issue? If so please provide a minimal repro so we can investigate. Thanks!

lahirumaramba avatar Feb 08 '22 19:02 lahirumaramba

Closing due to inactivity.

lahirumaramba avatar Dec 19 '22 22:12 lahirumaramba