diff --git a/src/Firebase.Auth/Firebase.Auth.csproj b/src/Firebase.Auth/Firebase.Auth.csproj index be3c476..47837e6 100644 --- a/src/Firebase.Auth/Firebase.Auth.csproj +++ b/src/Firebase.Auth/Firebase.Auth.csproj @@ -3,12 +3,10 @@ netstandard2.0 Firebase.Auth.Rest - 1.1.0-beta - Chris Paynter + 1.1.1-beta + Chris Paynter, Florian Kriegl A .NET API client for Firebase Rest Authentication API that follows Google's API spec as precisely as possible. - false First release - firebase auth 1.1.0-beta true diff --git a/src/Firebase.Auth/FirebaseAuthService.cs b/src/Firebase.Auth/FirebaseAuthService.cs index 895e2d9..13f27c0 100644 --- a/src/Firebase.Auth/FirebaseAuthService.cs +++ b/src/Firebase.Auth/FirebaseAuthService.cs @@ -11,7 +11,7 @@ namespace Firebase.Auth /// /// Service for connecting and communicating with the Firebase Auth REST API /// - public class FirebaseAuthService: IFirebaseAuthService, IDisposable + public class FirebaseAuthService : IFirebaseAuthService, IDisposable { private FirebaseAuthOptions options; private readonly HttpClient client; @@ -63,6 +63,30 @@ public async Task VerifyRefreshToken(VerifyRefreshTo return await Post(SecureTokenUrl(), request); } + /// + /// Sends a password change request to the provided user (id token) + /// + public async Task SendVerification(SendVerificationEmailRequest request) + { + return await Post(RelyingPartyUrl("getOobConfirmationCode"), request); + } + + /// + /// Sends a password change request to the provided user (id token) + /// + public async Task PasswordChange(ChangePasswordRequest request) + { + return await Post(RelyingPartyUrl("setAccountInfo"), request); + } + + /// + /// Gets the data of a specific account + /// + public async Task GetUserData(GetUserDataRequest request) + { + return await Post(RelyingPartyUrl("getAccountInfo"), request); + } + private async Task Post(string endpoint, object request) where TResponse : class { string responseJson = ""; diff --git a/src/Firebase.Auth/IFirebaseAuthService.cs b/src/Firebase.Auth/IFirebaseAuthService.cs index 76a2255..3d392a6 100644 --- a/src/Firebase.Auth/IFirebaseAuthService.cs +++ b/src/Firebase.Auth/IFirebaseAuthService.cs @@ -23,5 +23,20 @@ public interface IFirebaseAuthService /// Verifies the user via refresh token. /// Task VerifyRefreshToken(VerifyRefreshTokenRequest request); + + /// + /// Sends a verification email to the provided email address + /// + Task SendVerification(SendVerificationEmailRequest request); + + /// + /// Sends a password change request to the provided user (id token) + /// + Task PasswordChange(ChangePasswordRequest request); + + /// + /// Gets the data of a specific account + /// + Task GetUserData(GetUserDataRequest request); } } diff --git a/src/Firebase.Auth/Payloads/ChangePasswordRequest.cs b/src/Firebase.Auth/Payloads/ChangePasswordRequest.cs new file mode 100644 index 0000000..43da2d2 --- /dev/null +++ b/src/Firebase.Auth/Payloads/ChangePasswordRequest.cs @@ -0,0 +1,24 @@ +using System; +namespace Firebase.Auth.Payloads +{ + /// + /// You can change a user's password by issuing an HTTP POST request to the Auth setAccountInfo endpoint. + /// + public class ChangePasswordRequest : BaseRequest + { + /// + /// A Firebase Auth ID token for the user. + /// + public string IdToken { get; set; } + + /// + /// User's new password. + /// + public string Password { get; set; } + + /// + /// Whether or not to return an ID and refresh token. + /// + public string ReturnSecureToken { get; set; } + } +} diff --git a/src/Firebase.Auth/Payloads/ChangePasswordResponse.cs b/src/Firebase.Auth/Payloads/ChangePasswordResponse.cs new file mode 100644 index 0000000..a617a1b --- /dev/null +++ b/src/Firebase.Auth/Payloads/ChangePasswordResponse.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; + +namespace Firebase.Auth.Payloads +{ + /// + /// You can change a user's password by issuing an HTTP POST request to the Auth setAccountInfo endpoint. + /// + public class ChangePasswordResponse : BaseRequest + { + /// + /// The request type, always "identitytoolkit#SetAccountInfoResponse". + /// + public string kind { get; set; } + + /// + /// The uid of the current user. + /// + public string localId { get; set; } + + /// + /// User's email address. + /// + public string email { get; set; } + + /// + /// Hash version of password. + /// + public string passwordHash { get; set; } + + /// + /// List of all linked provider objects which contain "providerId" and "federatedId". + /// + public IList providerUserInfo { get; set; } + + /// + /// New Firebase Auth ID token for user. + /// + public string idToken { get; set; } + + /// + /// A Firebase Auth refresh token. + /// + public string refreshToken { get; set; } + + /// + /// The number of seconds in which the ID token expires. + /// + public string expiresIn { get; set; } + } + + public class ProviderUserInfo + { + /// + /// + /// + public string providerId { get; set; } + /// + /// + /// + public string federatedId { get; set; } + } +} diff --git a/src/Firebase.Auth/Payloads/GetUserDataRequest.cs b/src/Firebase.Auth/Payloads/GetUserDataRequest.cs new file mode 100644 index 0000000..bba31b5 --- /dev/null +++ b/src/Firebase.Auth/Payloads/GetUserDataRequest.cs @@ -0,0 +1,14 @@ +using System; +namespace Firebase.Auth.Payloads +{ + /// + /// You can get a user's data by issuing an HTTP POST request to the Auth getAccountInfo endpoint. + /// + public class GetUserDataRequest : BaseRequest + { + /// + /// The Firebase ID token of the account. + /// + public string IdToken { get; set; } + } +} diff --git a/src/Firebase.Auth/Payloads/GetUserDataResponse.cs b/src/Firebase.Auth/Payloads/GetUserDataResponse.cs new file mode 100644 index 0000000..e0ef810 --- /dev/null +++ b/src/Firebase.Auth/Payloads/GetUserDataResponse.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; + +namespace Firebase.Auth.Payloads +{ + public class GetUserDataResponse : BaseResponse + { + /// + /// The request type, always "identitytoolkit#GetAccountInfoResponse". + /// + public string kind { get; set; } + + /// + /// The account associated with the given Firebase ID token. Check below for more details. + /// + public IList users { get; set; } + } + + public class ProviderUserData + { + public string providerId { get; set; } + public string displayName { get; set; } + public string photoUrl { get; set; } + public string federatedId { get; set; } + public string email { get; set; } + public string rawId { get; set; } + public string screenName { get; set; } + } + + public class User + { + /// + /// The uid of the current user. + /// + public string localId { get; set; } + + /// + /// The email of the account. + /// + public string email { get; set; } + + /// + /// Whether or not the account's email has been verified. + /// + public bool emailVerified { get; set; } + + /// + /// The display name for the account. + /// + public string displayName { get; set; } + + /// + /// List of all linked provider objects which contain "providerId" and "federatedId". + /// + public IList providerUserInfo { get; set; } + + /// + /// The photo Url for the account. + /// + public string photoUrl { get; set; } + + /// + /// Hash version of password. + /// + public string passwordHash { get; set; } + + /// + /// The timestamp, in milliseconds, that the account password was last changed. + /// + public double passwordUpdatedAt { get; set; } + + /// + /// The timestamp, in seconds, which marks a boundary, before which Firebase ID token are considered revoked. + /// + public string validSince { get; set; } + + /// + /// Whether the account is disabled or not. + /// + public bool disabled { get; set; } + + /// + /// The timestamp, in milliseconds, that the account last logged in at. + /// + public string lastLoginAt { get; set; } + + /// + /// The timestamp, in milliseconds, that the account was created at. + /// + public string createdAt { get; set; } + + /// + /// Whether the account is authenticated by the developer. + /// + public bool customAuth { get; set; } + } +} diff --git a/src/Firebase.Auth/Payloads/SendVerificationEmailRequest.cs b/src/Firebase.Auth/Payloads/SendVerificationEmailRequest.cs new file mode 100644 index 0000000..9f0b464 --- /dev/null +++ b/src/Firebase.Auth/Payloads/SendVerificationEmailRequest.cs @@ -0,0 +1,16 @@ +using System; +namespace Firebase.Auth.Payloads +{ + public class SendVerificationEmailRequest : BaseRequest + { + /// + /// The type of confirmation code to send. Should always be "VERIFY_EMAIL". + /// + public string RequestType { get; set; } + + /// + /// The Firebase ID token of the user to verify. + /// + public string IdToken { get; set; } + } +} diff --git a/src/Firebase.Auth/Payloads/SendVerificationEmailResponse.cs b/src/Firebase.Auth/Payloads/SendVerificationEmailResponse.cs new file mode 100644 index 0000000..c0b5e91 --- /dev/null +++ b/src/Firebase.Auth/Payloads/SendVerificationEmailResponse.cs @@ -0,0 +1,15 @@ +namespace Firebase.Auth.Payloads +{ + public class SendVerificationEmailResponse : BaseResponse + { + /// + /// The request type, always "identitytoolkit#GetOobConfirmationCodeResponse". + /// + public string Kind { get; set; } + + /// + /// The email of the account. + /// + public string Email { get; set; } + } +}