Closed floppydisken closed 3 years ago
Note: In the future please use StackOverflow for API usage and debugging questions.
There are couple of issues in the above code. First, the following deserialization logic doesn't seem to work:
var accessTokenObject = new { tokens = new { access_token = "", id_token = "" } };
var deserializedFirebaseConfig = JsonConvert.DeserializeAnonymousType(
firebaseConfigAsRawJson,
accessTokenObject
);
var accessToken = accessTokenObject.tokens.access_token;
I had to read the acccess_token from deserializedFirebaseConfig
instead.
Secondly, the project ID is required configuration for accessing Auth APIs. So you must pass it explicitly via AppOptions
.
Once I fixed those issues, I was able to observe the same error as you. But this is only because the access_token written to the Firebase config file was expired (it's only valid for an hour). So I ran firebase logout
followed by firebase login
to force a new token to be written to the config file. Then my test code (shown below) ran without any issues:
static void Main(string[] args)
{
FirebaseApp.Create(new AppOptions {
Credential = FirebaseUtils.LoadGoogleCredentials(),
ProjectId = MyProjectId,
});
var users = FirebaseAuth.DefaultInstance.GetUserAsync(MyUid).Result;
Console.WriteLine(users.Email);
}
Thank you for clarifying. I actually thought there was an issue with the library, since it seemed strange to me that I could access my projects through the firebase-tools with what seemed like the access token provided by the config, hence why I posted the issue here. I'll pass it by stackoverflow first next time. The logout and login works like a charm.
Environment description
Steps to reproduce:
I'm trying to authenticate the FirebaseAdmin calls using the
firebase-tools
access token. To do this I'm loading the configstore firebase-tools.json file and reading the access token. Then using the project-id returned byfirebase use --non-interactive
to tell FirebaseAdmin which project I want to operate on. However this results in an authentication error and I'm not sure why it fails.firebase login
.firebase use <project-id>
Run the following code:
And use it like so
Throws
I thought I was clever integrating the authentication with firebase-tools, but it turns out it doesn't work. I want to use firebase-tools to easily switch between projects. In particular I have a development firebase-project for messing about and a production project for the serious stuff. This is to serve as an alternative to creating service-credentials-picker-logic. I do not really understand why I'm getting this error. It's as if the credentials are not applied to the request if the GoogleCredential is generated from an access token.
Can anyone shed some light on why this is failing?