Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email Verification Implementation Help #203

Open
koddek opened this issue Jul 26, 2023 · 1 comment
Open

Email Verification Implementation Help #203

koddek opened this issue Jul 26, 2023 · 1 comment

Comments

@koddek
Copy link

koddek commented Jul 26, 2023

Ok so I am attempting to implement Email Verification to this project. So far I have the REST url, and some classes:

internal static class Endpoints
{
    // ...
    public const string GoogleEmailUrl = "https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key={0}";
}

public class VerifyEmailRequest
{
    public const string EmailVerificationType = "VERIFY_EMAIL";

    public VerifyEmailRequest()
    {
        this.RequestType = EmailVerificationType;
    }

    public string IdToken { get; set; }

    public string RequestType { get; set; }
}

public class VerifyEmailResponse
{
    public string Email { get; set; }
}

public class VerifyEmail : FirebaseRequestBase<VerifyEmailRequest, VerifyEmailResponse>
{
    public VerifyEmail(FirebaseAuthConfig config) : base(config)
    {
    }

    protected override string UrlFormat => Endpoints.GooglePasswordUrl;
}

Where do I go from here? I would like to have a method in the FirebaseAuthClient class that says VerifyEmail(email), where an email is sent to the provided email address with a link that verifies the user when they click on it.

@asarr22
Copy link

asarr22 commented Aug 7, 2023

Hi, you can add a method to your project to send an activation email to the email address after Signing Up . When Signing in, FirebaseAuthClient has a method to verify if the user has activated their email with:

var userInfo = FirebaseAuthHelper.GetUserInfo(Your FirebaseAuthClient);
             bool flag = userInfo.IsEmailVerified;
             if(flag)
            {
                  //if email is verified
            }     

A method that can send a verification email to a signed up email address:

using System.Net.Http.Headers;

        private const string FirebaseApiKey = "Your API KEY;
        private const string RequestUri = "https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=" + FirebaseApiKey;

        public static async Task SendVerificationEmailAsync(string USER TOKEN)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var content = new StringContent("{\"requestType\":\"VERIFY_EMAIL\",\"idToken\":\"" + idToken + "\"}");
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var response = await client.PostAsync(RequestUri, content);
                response.EnsureSuccessStatusCode();
            }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants