12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- using FirebaseAdmin . Auth . Internal ;
16
15
using Google . Apis . Auth . OAuth2 ;
17
16
using Google . Apis . Http ;
18
- using Google . Apis . Json ;
19
17
using Newtonsoft . Json . Linq ;
20
18
using System ;
21
- using System . Collections . Generic ;
22
- using System . Collections . ObjectModel ;
23
19
using System . Net . Http ;
24
20
using System . Threading . Tasks ;
25
21
@@ -31,33 +27,10 @@ namespace FirebaseAdmin.Auth
31
27
/// Google Identity Toolkit</a> via its REST API. This class does not hold any mutable state,
32
28
/// and is thread safe.
33
29
/// </summary>
34
- internal class FirebaseUserManager : IDisposable
30
+ internal class FirebaseUserManager : IDisposable
35
31
{
36
32
private const string INTERNAL_ERROR = "internal-error" ;
37
33
38
- // Map of server-side error codes to SDK error codes.
39
- // SDK error codes defined at: https://firebase.google.com/docs/auth/admin/errors
40
- private static readonly IReadOnlyDictionary < string , string > _errorCodes =
41
- new ReadOnlyDictionary < string , string > ( new Dictionary < string , string > ( )
42
- {
43
- { "CLAIMS_TOO_LARGE" , "claims-too-large" } ,
44
- { "CONFIGURATION_NOT_FOUND" , "project-not-found" } ,
45
- { "INSUFFICIENT_PERMISSION" , "insufficient-permission" } ,
46
- { "DUPLICATE_EMAIL" , "email-already-exists" } ,
47
- { "DUPLICATE_LOCAL_ID" , "uid-already-exists" } ,
48
- { "EMAIL_EXISTS" , "email-already-exists" } ,
49
- { "INVALID_CLAIMS" , "invalid-claims" } ,
50
- { "INVALID_EMAIL" , "invalid-email" } ,
51
- { "INVALID_PAGE_SELECTION" , "invalid-page-token" } ,
52
- { "INVALID_PHONE_NUMBER" , "invalid-phone-number" } ,
53
- { "PHONE_NUMBER_EXISTS" , "phone-number-already-exists" } ,
54
- { "PROJECT_NOT_FOUND" , "project-not-found" } ,
55
- { "USER_NOT_FOUND" , "user-not-found" } ,
56
- { "WEAK_PASSWORD" , "invalid-password" } ,
57
- { "UNAUTHORIZED_DOMAIN" , "unauthorized-continue-uri" } ,
58
- { "INVALID_DYNAMIC_LINK_DOMAIN" , "invalid-dynamic-link-domain" }
59
- } ) ;
60
-
61
34
private const string ID_TOOLKIT_URL = "https://identitytoolkit.googleapis.com/v1/projects/{0}" ;
62
35
63
36
private readonly ConfigurableHttpClient _httpClient ;
@@ -93,48 +66,24 @@ private async Task<JObject> PostAsync(string path, UserRecord user)
93
66
try
94
67
{
95
68
response = await _httpClient . PostJsonAsync ( requestUri , user , default ) ;
69
+ var json = await response . Content . ReadAsStringAsync ( ) ;
96
70
97
71
if ( response . IsSuccessStatusCode )
98
72
{
99
- return JObject . Parse ( await response . Content . ReadAsStringAsync ( ) ) ;
73
+ return JObject . Parse ( json ) ;
100
74
}
101
75
else
102
76
{
103
- await HandleHttpError ( response ) ;
104
- }
105
- }
106
- catch ( Exception )
107
- {
108
- throw new FirebaseException ( INTERNAL_ERROR ) ;
109
- }
110
- finally
111
- {
112
- if ( response != null )
113
- {
114
- response . Dispose ( ) ;
77
+ var error = "Response status code does not indicate success: "
78
+ + $ "{ ( int ) response . StatusCode } ({ response . StatusCode } )"
79
+ + $ "{ Environment . NewLine } { json } ";
80
+ throw new FirebaseException ( error ) ;
115
81
}
116
82
}
117
-
118
- return null ;
119
- }
120
-
121
- private async Task HandleHttpError ( HttpResponseMessage response )
122
- {
123
- try
83
+ catch ( HttpRequestException e )
124
84
{
125
- var errorResponse =
126
- NewtonsoftJsonSerializer . Instance . Deserialize < HttpErrorResponse > ( await response . Content . ReadAsStringAsync ( ) ) ;
127
- if ( _errorCodes . TryGetValue ( errorResponse . ErrorCode , out var code ) )
128
- {
129
- throw new FirebaseException ( code ) ;
130
- } ;
131
- }
132
- catch ( Exception )
133
- {
134
- // Ignored
85
+ throw new FirebaseException ( "Error while calling Firebase Auth service" , e ) ;
135
86
}
136
-
137
- throw new FirebaseException ( INTERNAL_ERROR ) ;
138
87
}
139
88
140
89
internal static FirebaseUserManager Create ( FirebaseApp app )
0 commit comments