예제 #1
0
        public async Task <TokenResponse> GetAccessToken(TokenRequest tokenRequest, Dictionary <string, List <string> > headers)
        {
            string tokenRequestUrl = Configuration["OrchestratorAPI:TokenUrl"];

            Utilities.WebUtility webUtility = new Utilities.WebUtility(tokenRequestUrl);
            var    body     = JsonConvert.SerializeObject(tokenRequest);
            string response = await webUtility.PostAsync(body, headers);

            TokenResponse tokenResponse = JsonConvert.DeserializeObject <TokenResponse>(response);

            return(tokenResponse);
        }
예제 #2
0
        public async Task <IActionResult> Callback([FromQuery] string code, [FromQuery] string state)
        {
            // Verify JWT token (contains a default redirect URI)
            var jwtPayloadStr = _jwtTokenVerificationService.Verify(state, _configuration["MondayAPI:SS"]);

            if (jwtPayloadStr.Contains("invalid") || jwtPayloadStr.Contains("expired"))
            {
                return(Unauthorized());
            }
            var jwtPayload = JsonConvert.DeserializeObject <JwtPayload>(jwtPayloadStr);

            // Get access token
            // var token = await monday.oauthToken(code, process.env.CLIENT_ID, process.env.CLIENT_SECRET);
            var request = new Utilities.WebUtility(_configuration["MondayAPI:AccessTokenUrl"]);

            //string response = await webUtility.PostAsync(bodyTemplateTrigger, new Dictionary<string, List<string>>() { { "Authorization", new List<string>() { wfInputReq.in_SS } } });

            // TODO - Store the token in a secure way in a way you'll can later on find it using the user ID.
            // For example: await tokenStoreService.storeToken(userId, token);

            return(Redirect(jwtPayload.backToUrl));
        }
예제 #3
0
        public async Task <IActionResult> ProcessOrder([FromBody] MondayApiRequest value, [FromQuery] ExecutionType executionType, [FromQuery] StartJobParamSearch jobParam)
        {
            var headerToken = Request.Headers["Authorization"];
            //JwtPayload JwtPayload = Redirect($"api/auth/PerformVerification?token={headerToken}");
            // Verify JWT token (contains a default redirect URI)
            var jwtPayloadStr = _jwtTokenVerificationService.Verify(headerToken, _configuration["MondayAPI:SS"]);

            if (jwtPayloadStr.Contains("invalid") || jwtPayloadStr.Contains("expired"))
            {
                return(Unauthorized());
            }
            var jwtPayload = JsonConvert.DeserializeObject <JwtPayload>(jwtPayloadStr);

            _accessToken = jwtPayload.shortLivedToken ?? _configuration["MondayAPI:AccessToken"];

            WorkflowInputRequest wfInputReq    = new WorkflowInputRequest();
            InboundFieldValues   inboundValues = value.Payload.InboundFieldValues;

            // Initialize workflow input values
            wfInputReq.in_ParentItemId = inboundValues.ItemId;
            wfInputReq.in_SS           = _configuration["MondayAPI:SS"];
            // Get webhook url based on the subscribed boards to trigger monday update after extract completion
            string boardId     = inboundValues.BoardId.ToString();
            var    subsPayload = await _storageService.GetAsync(boardId);

            wfInputReq.in_CompletionTriggerUrl = subsPayload?.Data?.WebhookUrl;

            // Get inputs
            Result <Item[]> items = await _mondayDataProvider.GetItemsDetails(_accessToken, wfInputReq.in_ParentItemId.ToString());

            try { wfInputReq.in_PoNumber = items?.Data.FirstOrDefault().ColumnValues.Where(c => c.Id == inboundValues.OrderColumnId)?.Single()?.Text; }
            catch (Exception) { wfInputReq.in_PoNumber = new Random().Next(10000, 99999).ToString(); }


            // Prepare inputs and start UiPath job
            string inputArgs = JsonConvert.SerializeObject(wfInputReq);

            jobParam.Process          = "Posting";
            jobParam.ProcessExecution = executionType;
            string postToValue = "SAP BAPI";

            try { postToValue = items?.Data.FirstOrDefault().ColumnValues.Where(c => c.Id == inboundValues.PostToColumnId)?.Single()?.Text; }
            catch (Exception) { }

            if (jobParam.ProcessExecution == ExecutionType.None)
            {
                await _uiPathOrchestratorService.StartJob(inputArgs, jobParam.Process, jobParam.Folder, jobParam.Machine);
            }
            else if (jobParam.ProcessExecution == ExecutionType.Foreground && postToValue != null)
            {
                wfInputReq.in_System = postToValue.Contains(Enum.GetName(typeof(Application), Application.SAP)) ? Enum.GetName(typeof(Application), Application.SAP) : "";
                if (wfInputReq.in_System == Application.SAP.ToString())
                {
                    wfInputReq.in_PostViaBapi = postToValue.Contains(Enum.GetName(typeof(SAP_Interaction), SAP_Interaction.BAPI)) ? "Y" : "N";
                }
                inputArgs = JsonConvert.SerializeObject(wfInputReq);
                await _uiPathOrchestratorService.StartJob(inputArgs, jobParam.Process, jobParam.ProcessExecution);
            }
            else
            {
                await _uiPathOrchestratorService.StartJob(inputArgs, jobParam.Process, jobParam.ProcessExecution);
            }

            // In case no document number
            var templateFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                            @$ "Workflows\SOPosting\templates\Payload\BodyTemplate_Order.txt");
            var bodyTemplateTrigger = await System.IO.File.ReadAllTextAsync(templateFile);

            bodyTemplateTrigger = bodyTemplateTrigger.Replace("<Document No.>", new Random().Next(10000, 99999).ToString()).Replace("<in_ParentItemId>", wfInputReq.in_ParentItemId.ToString());
            Utilities.WebUtility webUtility = new Utilities.WebUtility(wfInputReq.in_CompletionTriggerUrl);
            string response = await webUtility.PostAsync(bodyTemplateTrigger, new Dictionary <string, List <string> >() { { "Authorization", new List <string>()
                                                                                                                            {
                                                                                                                                wfInputReq.in_SS
                                                                                                                            } } });

            return(Ok());
        }