Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/appcheck #374

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feature/app-check/ReplacePlaceholders
  • Loading branch information
taeul committed Jan 29, 2024
commit ec540fde685425dd533920373ddcf450c6421cca
10 changes: 5 additions & 5 deletions FirebaseAdmin/FirebaseAdmin/AppCheck/AppCheckApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 23,12 @@ internal sealed class AppCheckApiClient : IDisposable

internal AppCheckApiClient(Args args)
{
string noProjectId = "Project ID is required to access app check service. Use a service account "
if (string.IsNullOrEmpty(args.ProjectId))
{
string noProjectId = "Project ID is required to access app check service. Use a service account "
"credential or set the project ID explicitly via AppOptions. Alternatively "
"you can set the project ID via the GOOGLE_CLOUD_PROJECT environment "
"variable.";
if (string.IsNullOrEmpty(args.ProjectId))
{
throw new FirebaseAppCheckException(
ErrorCode.InvalidArgument,
noProjectId,
Expand Down Expand Up @@ -216,7 216,7 @@ private string GetUrl(string appId)
{ "appId", appId },
};

return HttpUtils.FormatString(AppCheckUrlFormat, urlParams);
return StringUtils.ReplacePlaceholders(AppCheckUrlFormat, urlParams);
}

private int StringToMilliseconds(string duration)
Expand Down Expand Up @@ -244,7 244,7 @@ private string GetVerifyTokenUrl()
{ "projectId", this.projectId },
};

return HttpUtils.FormatString(OneTimeUseTokenVerificationUrlFormat, urlParams);
return StringUtils.ReplacePlaceholders(OneTimeUseTokenVerificationUrlFormat, urlParams);
}

internal sealed class Args
Expand Down
11 changes: 0 additions & 11 deletions FirebaseAdmin/FirebaseAdmin/Util/HttpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 30,6 @@ internal sealed class HttpUtils

private HttpUtils() { }

public static string FormatString(string str, Dictionary<string, string> urlParams)
{
string formatted = str;
foreach (var key in urlParams.Keys)
{
formatted = Regex.Replace(formatted, $"{{{key}}}", urlParams[key]);
}

return formatted;
}

internal static string EncodeQueryParams(IDictionary<string, object> queryParams)
{
var queryString = string.Empty;
Expand Down
21 changes: 21 additions & 0 deletions FirebaseAdmin/FirebaseAdmin/Util/StringUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace FirebaseAdmin.Util
{
internal class StringUtils
{
public static string ReplacePlaceholders(string str, Dictionary<string, string> urlParams)
{
string formatted = str;
foreach (var key in urlParams.Keys)
{
formatted = Regex.Replace(formatted, $"{{{key}}}", urlParams[key]);
}

return formatted;
}
}
}