Skip to content

Repositório de teste para realizar uma autenticação junto com o serviço do FireBase

Notifications You must be signed in to change notification settings

Matheuscara/AutenticacaoFirebase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutenticacaoFirebase

Repositório de teste para realizar uma autenticação junto com o serviço do FireBase

#Principais pontos de atenção:

startup.cs - (No caso do .NET 6.0 como parou de existir, implementar no Program.cs)

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
    {
        //Validation
        options.Authority = "https://securetoken.google.com/{ProjetoFireBase}";
        options.TokenValidationParameters = new TokenValidationParameters
        {
            //Params Validation
            ValidateIssuer = true,
            ValidIssuer = "https://securetoken.google.com/{ProjetoFireBase}",
            ValidateAudience = true,
            ValidAudience = "{ProjetoFireBase}",
            //Validation Life Time
            ValidateLifetime = true
        };
    }
);

//Mais abaixo usar o UseAuthorization do .NET
app.UseAuthorization();

Models:

    public class UserLogin
    {
        public string idToken { get; set; }
        public string email { get; set; }
        public string refreshToken { get; set; }
    }

    public class UserLoginBody
    {
        public string email { get; set; }
        public string password { get; set; }
        public bool returnSecureToken { get; set; }
    }

Service - (RestEasy):

    public interface IGetToken
    {
        [Post("/v1/accounts:signInWithPassword?key={projectFireBaseCode}")]
        Task<UserLogin> GetUserAsync([Body] UserLoginBody UserLoginBody);
    }

Controller - (Task):

        [HttpPost]
        [Route("Api")]
        public async Task<UserLogin> CreateBearerToken(string username, string password, bool returnSecureToken)
        {
            UserLoginBody body = new UserLoginBody();
            body.email = username;
            body.password = password;
            body.returnSecureToken = returnSecureToken;
            

            IGetToken api = RestEase.RestClient.For<IGetToken>("https://identitytoolkit.googleapis.com");
            UserLogin tokenResponse = await api.GetUserAsync(body);
            return tokenResponse;
        }

About

Repositório de teste para realizar uma autenticação junto com o serviço do FireBase

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages