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

added mock authentication #3

Merged
merged 1 commit into from
May 21, 2020
Merged
Changes from all commits
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
24 changes: 19 additions & 5 deletions ImageRecognitionFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static class ImageRecognitionFunction
private static readonly string endpoint = Environment.GetEnvironmentVariable("ENTITY_SEARCH_ENDPOINT");



[FunctionName("AnalyseImage")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", "options", Route = null)] HttpRequest req, ILogger log)
{
Expand Down Expand Up @@ -67,12 +68,12 @@ public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anon
log.LogInformation(uri);


// The other content types you can use are "application/json"
// Asynchronously call the REST API method.
var formatter = new JsonMediaTypeFormatter();
// The other content types you can use are "application/json"
// Asynchronously call the REST API method.
var formatter = new JsonMediaTypeFormatter();

response = await client.PostAsync(uri, new { url = imageUrl }, formatter);

response = await client.PostAsync(uri, new { url = imageUrl }, formatter);


// Asynchronously get the JSON response.
string contentString = await response.Content.ReadAsStringAsync();
Expand All @@ -90,6 +91,19 @@ public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anon
? (ActionResult)new OkObjectResult("Success")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}

[FunctionName("authenticate")]
public static async Task<IActionResult> VerifyToken([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", "options", Route = null)] HttpRequest req, ILogger log)
{
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);

string token = data?.token;

return new OkObjectResult( new { token, message = "Authentication Mocked Successfully" });

}

}

}