Skip to content

Commit a95bf7f

Browse files
committed
Default token to be null in Invoke calls to allow Authorization to be passed solely via Headers.
1 parent 2cb1f55 commit a95bf7f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Functions/Client.cs

+17-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ public class Client
2020
/// <param name="token">Anon Key.</param>
2121
/// <param name="options">Options</param>
2222
/// <returns></returns>
23-
public static async Task<HttpContent> RawInvoke(string url, string token, InvokeFunctionOptions options = null) => (await HandleRequest(url, token, options)).Content;
23+
public static async Task<HttpContent> RawInvoke(string url, string token = null, InvokeFunctionOptions options = null) => (await HandleRequest(url, token, options)).Content;
2424

25-
public static async Task<string> Invoke(string url, string token, InvokeFunctionOptions options = null)
25+
/// <summary>
26+
/// Invokes a function and returns the Text content of the response.
27+
/// </summary>
28+
/// <param name="url">Url of the function to invoke</param>
29+
/// <param name="token">Anon Key.</param>
30+
/// <param name="options">Options</param>
31+
/// <returns></returns>
32+
public static async Task<string> Invoke(string url, string token = null, InvokeFunctionOptions options = null)
2633
{
2734
var response = await HandleRequest(url, token, options);
2835

@@ -37,7 +44,7 @@ public static async Task<string> Invoke(string url, string token, InvokeFunction
3744
/// <param name="token">Anon Key.</param>
3845
/// <param name="options">Options</param>
3946
/// <returns></returns>
40-
public static async Task<T> Invoke<T>(string url, string token, InvokeFunctionOptions options = null)
47+
public static async Task<T> Invoke<T>(string url, string token = null, InvokeFunctionOptions options = null)
4148
{
4249
var response = await HandleRequest(url, token, options);
4350

@@ -54,14 +61,18 @@ public static async Task<T> Invoke<T>(string url, string token, InvokeFunctionOp
5461
/// <param name="options"></param>
5562
/// <returns></returns>
5663
/// <exception cref="RequestException"></exception>
57-
private static async Task<HttpResponseMessage> HandleRequest(string url, string token, InvokeFunctionOptions options)
64+
private static async Task<HttpResponseMessage> HandleRequest(string url, string token = null, InvokeFunctionOptions options)
5865
{
5966
if (options == null)
6067
{
6168
options = new InvokeFunctionOptions();
6269
}
6370

64-
options.Headers["Authorization"] = $"Bearer {token}";
71+
if (!string.IsNullOrEmpty(token))
72+
{
73+
options.Headers["Authorization"] = $"Bearer {token}";
74+
}
75+
6576
options.Headers["X-Client-Info"] = Util.GetAssemblyVersion();
6677

6778
var builder = new UriBuilder(url);
@@ -114,7 +125,7 @@ public RequestException(HttpResponseMessage response, ErrorResponse error) : bas
114125
/// <summary>
115126
/// Options that can be supplied to a function invocation.
116127
///
117-
/// Note: If Headers.Authorization is set, it will later be overriden by the token supplied in the method call.
128+
/// Note: If Headers.Authorization is set, it can be later overriden if a token is supplied in the method call.
118129
/// </summary>
119130
public class InvokeFunctionOptions
120131
{

0 commit comments

Comments
 (0)