Beispiel #1
0
        private IDictionary <string, string> GetPayload()
        {
            var jwtPayload = _jwtPayload.GetPayload();
            var rsaParams  = Credentials.GetRSAParams();

            string jwtToken;

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(rsaParams);
                jwtToken = Configuration.JwtTokenProvider.Encode(jwtPayload, rsa);
            }

            var permissionPayload = new PermissionAuthPayloadGenerator(jwtToken).GetPayload();

            return(permissionPayload);
        }
        public async Task <FirebaseAccessToken> Send2LOTokenRequestAsync()
        {
            var jwtPayload = _jwtPayload.GetPayload();
            var rsaParams  = _serviceAccountCredentials.GetRSAParams();

            string jwtToken;

            using (var rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(rsaParams);
                jwtToken = _firebaseConfig.JwtTokenProvider.Encode(jwtPayload, rsa);
            }

            var permissionPayload = new PermissionAuthPayloadGenerator(jwtToken).GetPayload();

            var urlEncodedPayload = new FormUrlEncodedContent(permissionPayload);


            HttpResponseMessage response = await PostAsync(_firebaseConfig.GoogleOAuthTokenPath, urlEncodedPayload);

            await response.EnsureSuccessStatusCodeAsync();

            if (response.Content == null)
            {
                throw new FirebaseHttpException("Authentication failed, empty response content from firebase server");
            }
            var strinRepresentation = await response.Content.ReadAsStringAsync();

            var serializationSettings = new JsonSerializerSettings()
            {
                ContractResolver = new FirebaseAccessTokenContractResolver()
            };

            _accessToken = JsonConvert.DeserializeObject <FirebaseAccessToken>(strinRepresentation, serializationSettings);
            if (_accessToken == null)
            {
                throw new FirebaseHttpException("Authentication failed, unsupported content type was returned from firebase server");
            }
            return(_accessToken);
        }