Exemple #1
0
        public static async Task <dynamic> Get2LeggedTokenAsync(Scope[] scopes)
        {
            TwoLeggedApi oauth     = new TwoLeggedApi();
            string       grantType = "client_credentials";
            dynamic      bearer    = await oauth.AuthenticateAsync(
                Credentials.GetAppSetting("FORGE_CLIENT_ID"),
                Credentials.GetAppSetting("FORGE_CLIENT_SECRET"),
                grantType,
                scopes);

            return(bearer);
        }
Exemple #2
0
        public string GetOAuthURL()
        {
            // prepare the sign in URL
            Scope[]        scopes          = { Scope.DataRead };
            ThreeLeggedApi _threeLeggedApi = new ThreeLeggedApi();
            string         oauthUrl        = _threeLeggedApi.Authorize(
                Credentials.GetAppSetting("FORGE_CLIENT_ID"),
                oAuthConstants.CODE,
                Credentials.GetAppSetting("FORGE_CALLBACK_URL"),
                new Scope[] { Scope.DataRead, Scope.DataCreate, Scope.DataWrite, Scope.ViewablesRead });

            return(oauthUrl);
        }
Exemple #3
0
 public dynamic GetClientID()
 {
     return(new { id = Credentials.GetAppSetting("FORGE_CLIENT_ID") });
 }
        private async Task <IActionResult> PostGoodPractices(string projectId, int version, string hubId, string rvt, string guid)
        {
            // basic input validation
            string activityName = "cyBnhhxpfsbhGC1jv4CdyDSLwj912JA4.UpdateRVTParamActivity+dev";
            //var projectId = (string)rvt.projectId;
            //var version = (int)rvt.version;

            // OAuth token
            dynamic oauth = await OAuthController.GetInternalAsync();

            // upload file to OSS Bucket
            // 1. ensure bucket existis
            string     bucketKey = NickName.ToLower() + "-designautomation";
            BucketsApi buckets   = new BucketsApi();

            buckets.Configuration.AccessToken = oauth.access_token;
            try
            {
                PostBucketsPayload bucketPayload = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient);
                await buckets.CreateBucketAsync(bucketPayload, "US");
            }
            catch { };

            // prepare workitem arguments
            // 1. input file
            //var guid = (string)rvt.guid;
            var rvtName = rvt;//(string)rvt.rvtName;
            XrefTreeArgument inputFileArgument = new XrefTreeArgument()
            {
                Url       = $"https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/{guid}",
                LocalName = "myzip",
                PathInZip = rvtName,
                Headers   = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + oauth.access_token }
                }
            };

            // 2. input json
            dynamic inputJson = new JObject();

            inputJson.HubId     = hubId;
            inputJson.ProjectId = projectId;
            inputJson.Version   = version;
            var inputJsonArgument = new XrefTreeArgument()
            {
                Url = "data:application/json, " + ((JObject)inputJson).ToString(Formatting.None).Replace("\"", "'")
            };

            // 3. output file
            string           outputFileNameOSS  = string.Format("{0}_output_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), Path.GetFileName("OutputFile.json")); // avoid overriding
            XrefTreeArgument outputFileArgument = new XrefTreeArgument()
            {
                Url     = string.Format("https://developer.api.autodesk.com/oss/v2/buckets/{0}/objects/{1}", bucketKey, outputFileNameOSS),
                Verb    = Verb.Put,
                Headers = new Dictionary <string, string>()
                {
                    { "Authorization", "Bearer " + oauth.access_token }
                }
            };

            // prepare & submit workitem
            // the callback contains the connectionId (used to identify the client) and the outputFileName of this workitem
            string   callbackUrl  = string.Format("{0}/api/forge/callback/mongo?id={1}&outputFileName={2}", Credentials.GetAppSetting("FORGE_WEBHOOK_URL"), "", outputFileNameOSS);
            WorkItem workItemSpec = new WorkItem()
            {
                ActivityId = activityName,
                Arguments  = new Dictionary <string, IArgument>()
                {
                    { "inputFile", inputFileArgument },
                    { "inputJson", inputJsonArgument },
                    { "outputFile", outputFileArgument },
                    { "onComplete", new XrefTreeArgument {
                          Verb = Verb.Post, Url = callbackUrl
                      } }
                }
            };

            WorkItemStatus workItemStatus = await _designAutomation.CreateWorkItemAsync(workItemSpec);

            return(Ok(new { WorkItemId = workItemStatus.Id }));
        }