Comments (5)
Hi, can you be more specific? What do you want to achieve? Do you want to have your own server which would be authenticating users?
from firebase-authentication-dotnet.
Hi, I have my own server to authenticate the users and return a JWT token.
I'm using the firebase SDK for iOS to authenticate my user using my server JWT token like this:
FIRAuth.auth()?.signInWithCustomToken(userMyServerToken) { (user, error) in
}
it's working on iOS, I need do the same thing with my c# application.
from firebase-authentication-dotnet.
you don't need to use this package to use your custom JWT token. You can use the FirebaseDatabase.net package directly with the token you get from your service
from firebase-authentication-dotnet.
I couldn't get it to work using the (v3) custom token directly. And according to documentation it shouldn't. The custom tokens are different from firebase tokens and the admin SDK's method for verifying tokens does not work on custom tokens. The client needs to exchange it for a firebase token first.
Observing the JS client library, I figured out a possible implementation:
private const string GoogleCustomAuthUrl = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key={0}";
public async Task<FirebaseAuthLink> SignInWithCustomTokenAsync(string customToken)
{
string content = string.Format("{{\"token\":\"{0}\",\"returnSecureToken\":true}}", new object[1]
{
(object) customToken
});
FirebaseAuthLink firebaseAuthLink = await this.ExecuteWithPostContentAsync(GoogleCustomAuthUrl, content).ConfigureAwait(false);
return firebaseAuthLink;
}
Unfortunately the user object stays empty. So I quickly put together a second method, again immitating the js client's behaviour:
private User GetUser(string idToken)
{
var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/identitytoolkit/v3/relyingparty/getAccountInfo?key=" + this.authConfig.ApiKey);
request.ContentType = "application/json";
request.Method = "POST";
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
idToken = idToken
});
streamWriter.Write(json);
}
var response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
JObject resultJson = JObject.Parse(result);
IEnumerable<JToken> usersJson = resultJson["users"];
var user = JsonConvert.DeserializeObject<User>(usersJson.First().ToString());
return user;
}
}
and added a line into the first method:
firebaseAuthLink.User = GetUser(firebaseAuthLink.FirebaseToken);
Any thoughts or experiences? Any chance to make that part of your (awesome) lib?
from firebase-authentication-dotnet.
Feel free to make a PR, I will review it and accept it ;)
from firebase-authentication-dotnet.
Related Issues (20)
- (Enchancement) Support Local Storage & Async for IUserRepository HOT 1
- Possibility to check user password HOT 1
- Question: do you not support sign in with custom token? HOT 1
- Email verification HOT 7
- Posibility to change the token expiration HOT 1
- Phone Authentication
- Exception occured during Firebase Http request. HOT 1
- Check if DisplayName already exists HOT 1
- Need Help with login with Google in .NET MAUI HOT 1
- Email Verification Implementation Help HOT 1
- [Endpoints Migration] : identitytoolkit v3 needs to be migrated to something else HOT 1
- Is there a way to get the last time user logged in?
- Create Email and Password issue in .Net MAUI
- [.NET MAUI] How implement "OpenBrowserAndWaitForRedirectToAuthDomain" HOT 2
- I can't get FetchSignInMethodsForEmailAsync to work HOT 2
- How to persist authentication across app restarts ? HOT 6
- Allow FirebaseAuthConfig.RedirectUri to be configurable
- Observed in version 3.7.2 : Parsing error when the password ends (or maybe contains also) a backslash \ HOT 2
- How do you set a photo Url in version 4.1.0?
- Refresh Token Implementation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from firebase-authentication-dotnet.