Exemplo n.º 1
0
        /// <summary>
        /// Validates the current request
        /// </summary>
        /// <param name="args">An <see cref="ValidateCredentialTokenFunctionArgs"/> instance specifying the location of the client configuration in Azure storage.</param>
        /// <returns>OK with json '{"valid": true || false}'</returns>
        public HttpResponseMessage Execute(ValidateCredentialTokenFunctionArgs args)
        {
            var responseObject = new { valid = false };

            //If the input is bad in any way there will be an error and the response shall be OK with json {"valid":false}
            try
            {
                if (!_queryParams.ContainsKey("token") || !_queryParams.ContainsKey("cId"))
                {
                    throw new Exception();
                }
                var clientConfig = GetConfiguration(_queryParams["cId"]);

                //Will throw if the token can't be decrypted
                var ctx = CredentialedSharePointConnectionInfo.GetSharePointClientContext(_queryParams["token"],
                                                                                          clientConfig.CredentialedClientConfig.Password, clientConfig.CredentialedClientConfig.Salt);

                ctx.Load(ctx.Web);

                //Will throw if the credentials are no good
                ctx.ExecuteQuery();
                responseObject = new { valid = true };
            }
            catch
            {
                //ignored - if there is an exception the request is simply not valid
            }
            _response.StatusCode = HttpStatusCode.OK;
            _response.Content    = new StringContent((new JavaScriptSerializer()).Serialize(responseObject));
            _response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            return(_response);
        }
        public static Task <HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
        {
            Log(log, $"C# HTTP trigger function processed a request! RequestUri={req.RequestUri}");
            var func = new ValidateCredentialTokenHandler(req);

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

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

            return(Task.FromResult(func.Execute(ValidateCredentialTokenFunctionArgs)));
        }
Exemplo n.º 3
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "ValidateCredentialToken")] HttpRequestMessage req, TraceWriter log)
        {
            Log(log, $"C# HTTP trigger function processed a request! RequestUri={req.RequestUri}");
            var func = new ValidateCredentialTokenHandler(req);

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

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

            return(await Task.Run(() => func.Execute(validateCredentialTokenFunctionArgs)));
        }