private void SendOAuth(ServiceAccountCredential.OAuthRequest request) { Services.Logging.LogMessage(PlatformLogLevel.Debug, string.Format("Sending OAuth request to {0}", base.TokenServerUrl)); FirebaseHttpRequest firebaseHttpRequest = Services.HttpFactory.OpenConnection(new Uri(base.TokenServerUrl)); firebaseHttpRequest.SetRequestMethod("POST"); firebaseHttpRequest.SetRequestProperty(FirebaseHttpRequest.HeaderContentType, "application/x-www-form-urlencoded"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("grant_type="); stringBuilder.Append("urn:ietf:params:oauth:grant-type:jwt-bearer"); stringBuilder.Append("&"); stringBuilder.Append("assertion="); stringBuilder.Append(request.Assertion); byte[] bytes = Encoding.ASCII.GetBytes(stringBuilder.ToString()); firebaseHttpRequest.OutputStream.Write(bytes, 0, bytes.Length); if (firebaseHttpRequest.ResponseCode >= 200 && firebaseHttpRequest.ResponseCode < 300) { Services.Logging.LogMessage(PlatformLogLevel.Debug, string.Format("OAuth request to {0} completed with code {1}", base.TokenServerUrl, firebaseHttpRequest.ResponseCode.ToString())); StreamReader streamReader = new StreamReader(firebaseHttpRequest.InputStream); request.ResponseBody = streamReader.ReadToEnd(); Services.Logging.LogMessage(PlatformLogLevel.Debug, string.Format("OAuth request to {0} completed with msg {1}", base.TokenServerUrl, request.ResponseBody)); } else { Services.Logging.LogMessage(PlatformLogLevel.Error, string.Format("OAuth request to {0} failed with code {1}", base.TokenServerUrl, firebaseHttpRequest.ResponseCode.ToString())); StreamReader streamReader2 = new StreamReader(firebaseHttpRequest.ErrorStream); string arg = streamReader2.ReadToEnd(); Services.Logging.LogMessage(PlatformLogLevel.Debug, string.Format("OAuth request to {0} failed with msg {1}", base.TokenServerUrl, arg)); request.ResponseBody = null; } }
private static X509CertificateCollection DecodeWebRootCollection(IFirebaseAppPlatform app) { Uri certUpdateUrl = Services.AppConfig.GetCertUpdateUrl(app); if (certUpdateUrl != null) { FirebaseHttpRequest firebaseHttpRequest = Services.HttpFactory.OpenConnection(certUpdateUrl); firebaseHttpRequest.SetRequestMethod("GET"); if (firebaseHttpRequest.ResponseCode >= 200 && firebaseHttpRequest.ResponseCode < 300) { Services.Logging.LogMessage(PlatformLogLevel.Debug, string.Format("updated certs from {0} completed with code {1}", certUpdateUrl, firebaseHttpRequest.ResponseCode.ToString())); StreamReader streamReader = new StreamReader(firebaseHttpRequest.InputStream); return(InstallRootCerts.DecodeCertificateCollectionFromString(streamReader.ReadToEnd())); } Services.Logging.LogMessage(PlatformLogLevel.Error, string.Format("error loading updated certs from {0} with code {1}", certUpdateUrl, firebaseHttpRequest.ResponseCode.ToString())); } else { Services.Logging.LogMessage(PlatformLogLevel.Warning, "No root cert url to download."); } return(new X509CertificateCollection()); }