Beispiel #1
0
        public async Task TenantId()
        {
            var tenantConfig      = TestConfig.ForTenantAwareFirebaseAuth("test-tenant");
            var idTokenWithTenant = await tenantConfig.CreateIdTokenAsync();

            FirebaseAuth auth = (FirebaseAuth)TestConfig.ForFirebaseAuth().CreateAuth();

            var decoded = await auth.VerifyIdTokenAsync(idTokenWithTenant);

            tenantConfig.AssertFirebaseToken(decoded);
            Assert.Equal("test-tenant", decoded.TenantId);
        }
        public async Task UseAfterDelete()
        {
            var app = FirebaseApp.Create(new AppOptions()
            {
                Credential = mockCredential
            });
            FirebaseAuth auth = FirebaseAuth.DefaultInstance;

            app.Delete();
            await Assert.ThrowsAsync <InvalidOperationException>(
                async() => await auth.CreateCustomTokenAsync("user"));

            await Assert.ThrowsAsync <InvalidOperationException>(
                async() => await auth.VerifyIdTokenAsync("user"));
        }
Beispiel #3
0
        public async Task <string> CheckFireBaseUserToken(string idToken)
        {
            string ret = "";

            try
            {
                FirebaseToken decodedToken = await authInstance.VerifyIdTokenAsync(idToken);

                ret = decodedToken.Uid;
            }
            catch (Exception ex)
            {
                SaveLog($"[Error] FireBaseHandler::CheckFireBaseUserToken, Catch Error, Msg:{ex.Message}");
            }

            return(ret);
        }
Beispiel #4
0
        public async Task <string> VerifyIdTokenAsync(string token)
        {
            FirebaseToken decoded;

            try
            {
                decoded = await _firebase.VerifyIdTokenAsync(token);
            }
            catch (FirebaseAuthException ex)
            {
                throw new Exception($"ID {token} not authorized at Firebase", ex);
            }
            catch (Exception ex)
            {
                throw new Exception("Exception calling _firebase.VerifyIdTokenAsync", ex);
            }

            return(decoded.Uid);
        }
Beispiel #5
0
        public async Task UseAfterDelete()
        {
            var app = FirebaseApp.Create(new AppOptions()
            {
                Credential = MockCredential
            });
            FirebaseAuth auth = FirebaseAuth.DefaultInstance;

            app.Delete();
            await Assert.ThrowsAsync <InvalidOperationException>(
                async() => await auth.CreateCustomTokenAsync("user"));

            await Assert.ThrowsAsync <InvalidOperationException>(
                async() => await auth.VerifyIdTokenAsync("user"));

            await Assert.ThrowsAsync <InvalidOperationException>(
                async() => await auth.SetCustomUserClaimsAsync("user", null));

            await Assert.ThrowsAsync <InvalidOperationException>(
                async() => await auth.GetOidcProviderConfigAsync("oidc.provider"));
        }
        public async Task <ClaimsDto> VerifyTokenAsync(string jwt)
        {
            try
            {
                var token = await _firebaseApp.VerifyIdTokenAsync(jwt);

                var claimsDto = new ClaimsDto
                {
                    Subject  = token.Subject,
                    Audience = token.Audience,
                    Issuer   = token.Issuer,
                    ExpirationTimeSeconds = token.ExpirationTimeSeconds,
                    IssuedAtTimeSeconds   = token.IssuedAtTimeSeconds,
                    Claims = token.Claims
                };

                return(claimsDto);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Beispiel #7
0
        public async Task <string> GetUid(string accessToken)
        {
            FirebaseToken decodedToken = await _auth.VerifyIdTokenAsync(accessToken);

            return(decodedToken.Uid);
        }
Beispiel #8
0
 public async Task <FirebaseToken> VerifyIdToken(string idToken)
 {
     return(await auth.VerifyIdTokenAsync(idToken));
 }