/// <summary>
        /// Attempts to connect to SharePoint and creates a <see cref="CredentialedSharePointConnectionInfo"/> returned as application/json
        /// </summary>
        /// <param name="args">An <see cref="CreateCredentialTokenFunctionArgs"/> instance specifying the location of the client configuration in Azure storage.</param>
        public HttpResponseMessage Execute(CreateCredentialTokenFunctionArgs args)
        {
            //If the input is bad in any way there will be an error and the response shall be Unauthorized
            try
            {
                if (_credentialedSharePointConnectionInfo == null)
                {
                    throw new InvalidOperationException("The input didn't have connection info in json format");
                }
                var clientConfig = GetConfiguration(_credentialedSharePointConnectionInfo.ClientId);

                //This will throw if the connection info is no good
                _credentialedSharePointConnectionInfo.GetSharePointClientContext();

                var token = _credentialedSharePointConnectionInfo.GetEncryptedToken(clientConfig.CredentialedClientConfig.Password, clientConfig.CredentialedClientConfig.Salt);

                _response.StatusCode = HttpStatusCode.OK;
                _response.Content    = new StringContent($"{{\"credentialToken\":\"{token}\"}}");
                _response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                return(_response);
            }
            catch (Exception ex)
            {
                Log($"Error connecting {ex}");
                _response.StatusCode = HttpStatusCode.Unauthorized;
                return(_response);
            }
        }
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "CreateCredentialToken")] HttpRequestMessage req, TraceWriter log)
        {
            Log(log, $"C# HTTP trigger function processed a request! RequestUri={req.RequestUri}");
            var func = new CreateCredentialTokenHandler(req);

            func.FunctionNotify += (sender, args) => Log(log, args.Message);

            var createCredentialTokenFunctionArgs = new CreateCredentialTokenFunctionArgs
            {
                StorageAccount    = ConfigurationManager.AppSettings["ConfigurationStorageAccount"],
                StorageAccountKey = ConfigurationManager.AppSettings["ConfigurationStorageAccountKey"]
            };

            return(await Task.Run(() => func.Execute(createCredentialTokenFunctionArgs)));
        }
コード例 #3
0
        public static Task <HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
        {
            Log(log, $"C# HTTP trigger function processed a request! RequestUri={req.RequestUri}");
            var func = new CreateCredentialTokenHandler(req);

            func.FunctionNotify += (sender, args) => Log(log, args.Message);

            var CreateCredentialTokenFunctionArgs = new CreateCredentialTokenFunctionArgs()
            {
                StorageAccount    = ConfigurationManager.AppSettings["ConfigurationStorageAccount"],
                StorageAccountKey = ConfigurationManager.AppSettings["ConfigurationStorageAccountKey"]
            };

            return(Task.FromResult(func.Execute(CreateCredentialTokenFunctionArgs)));
        }