示例#1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "created")] HttpRequestMessage httpRequest,
            ILogger log)
        {
            if (httpRequest is null)
            {
                throw new ArgumentNullException(nameof(httpRequest));
            }

            var query = httpRequest.RequestUri.ParseQueryString();
            var code  = query["code"];

            if (string.IsNullOrEmpty(code))
            {
                throw new InvalidOperationException("Parameter 'code' is required in the query string.");
            }

            log.LogWarning($"GitHub code: {code ?? "null"}");

            var app = await github
                      .GetAppManifest(code)
                      .ConfigureAwait(false);

            if (app is null)
            {
                return(new NotFoundObjectResult("Failed to get GitHub App Manifiest from GitHub."));
            }

            return(new ContentResult
            {
                Content = Html(app),
                ContentType = "text/html"
            });
        }