diff --git a/Backend/Controllers/ModelDerivativeController.cs b/Backend/Controllers/ModelDerivativeController.cs
index 951cae1..db62d9d 100644
--- a/Backend/Controllers/ModelDerivativeController.cs
+++ b/Backend/Controllers/ModelDerivativeController.cs
@@ -1,6 +1,7 @@
using Autodesk.Forge;
using Autodesk.Forge.Model;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -9,6 +10,9 @@ namespace forgeSample.Controllers
[ApiController]
public class ModelDerivativeController : ControllerBase
{
+ private static IConfiguration _configuration;
+
+ public ModelDerivativeController(IConfiguration configuration) { _configuration = configuration; }
///
/// Start the translation job for a give bucketKey/objectName
///
@@ -18,7 +22,7 @@ namespace forgeSample.Controllers
[Route("api/forge/modelderivative/jobs")]
public async Task TranslateObject([FromBody] TranslateObjectModel objModel)
{
- dynamic oauth = await OAuthController.GetInternalAsync();
+ dynamic oauth = await OAuthController.GetInternalAsync(_configuration);
// prepare the payload
List outputs = new List()
diff --git a/Backend/Controllers/OAuthController.cs b/Backend/Controllers/OAuthController.cs
index ddf54b5..0ef6173 100644
--- a/Backend/Controllers/OAuthController.cs
+++ b/Backend/Controllers/OAuthController.cs
@@ -1,5 +1,6 @@
using Autodesk.Forge;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
using System;
using System.Threading.Tasks;
@@ -14,6 +15,9 @@ namespace forgeSample.Controllers
// them after the expires_in time (in seconds)
private static dynamic InternalToken { get; set; }
private static dynamic PublicToken { get; set; }
+ private static IConfiguration _configuration;
+
+ public OAuthController(IConfiguration configuration) { _configuration = configuration; }
///
/// Get access token with public (viewables:read) scope
@@ -24,7 +28,7 @@ namespace forgeSample.Controllers
{
if (PublicToken == null || PublicToken.ExpiresAt < DateTime.UtcNow)
{
- PublicToken = await Get2LeggedTokenAsync(new Scope[] { Scope.ViewablesRead });
+ PublicToken = await Get2LeggedTokenAsync(_configuration, new Scope[] { Scope.ViewablesRead });
PublicToken.ExpiresAt = DateTime.UtcNow.AddSeconds(PublicToken.expires_in);
}
return PublicToken;
@@ -33,11 +37,11 @@ namespace forgeSample.Controllers
///
/// Get access token with internal (write) scope
///
- public static async Task GetInternalAsync()
+ public static async Task GetInternalAsync(IConfiguration Configuration)
{
if (InternalToken == null || InternalToken.ExpiresAt < DateTime.UtcNow)
{
- InternalToken = await Get2LeggedTokenAsync(new Scope[] { Scope.BucketCreate, Scope.BucketRead, Scope.BucketDelete, Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.CodeAll });
+ InternalToken = await Get2LeggedTokenAsync(Configuration, new Scope[] { Scope.BucketCreate, Scope.BucketRead, Scope.BucketDelete, Scope.DataRead, Scope.DataWrite, Scope.DataCreate, Scope.CodeAll });
InternalToken.ExpiresAt = DateTime.UtcNow.AddSeconds(InternalToken.expires_in);
}
@@ -47,13 +51,13 @@ namespace forgeSample.Controllers
///
/// Get the access token from Autodesk
///
- private static async Task Get2LeggedTokenAsync(Scope[] scopes)
+ private static async Task Get2LeggedTokenAsync(IConfiguration Configuration, Scope[] scopes)
{
TwoLeggedApi oauth = new TwoLeggedApi();
string grantType = "client_credentials";
dynamic bearer = await oauth.AuthenticateAsync(
- GetAppSetting("FORGE_CLIENT_ID"),
- GetAppSetting("FORGE_CLIENT_SECRET"),
+ GetAppSetting(Configuration, "Forge:CLIENT_ID"),
+ GetAppSetting(Configuration, "Forge:CLIENT_SECRET"),
grantType,
scopes);
return bearer;
@@ -62,9 +66,9 @@ namespace forgeSample.Controllers
///
/// Reads appsettings from web.config
///
- public static string GetAppSetting(string settingKey)
+ public static string GetAppSetting(IConfiguration Configuration, string settingKey)
{
- return Environment.GetEnvironmentVariable(settingKey).Trim();
+ return Configuration.GetValue(settingKey).Trim();
}
}
}
\ No newline at end of file
diff --git a/Backend/Controllers/OSSController.cs b/Backend/Controllers/OSSController.cs
index 6a5cb26..f2c1e6f 100644
--- a/Backend/Controllers/OSSController.cs
+++ b/Backend/Controllers/OSSController.cs
@@ -3,6 +3,7 @@ using Autodesk.Forge.Model;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
@@ -13,9 +14,12 @@ namespace forgeSample.Controllers
public class OSSController : ControllerBase
{
private IWebHostEnvironment _env;
- public OSSController(IWebHostEnvironment env) { _env = env; }
- public string ClientId { get { return OAuthController.GetAppSetting("FORGE_CLIENT_ID").ToLower(); } }
+ private static IConfiguration _configuration;
+ public OSSController(IWebHostEnvironment env, IConfiguration configuration) { _env = env; _configuration = configuration; }
+ public string ClientId { get { return _configuration.GetValue("Forge:CLIENT_ID").ToLower(); } }
+
+
///
/// Return list of buckets (id=#) or list of objects (id=bucketKey)
///
@@ -24,7 +28,7 @@ namespace forgeSample.Controllers
public async Task> GetOSSAsync(string id)
{
IList nodes = new List();
- dynamic oauth = await OAuthController.GetInternalAsync();
+ dynamic oauth = await OAuthController.GetInternalAsync(_configuration);
if (id == "#") // root
{
@@ -81,7 +85,7 @@ namespace forgeSample.Controllers
public async Task CreateBucket([FromBody] CreateBucketModel bucket)
{
BucketsApi buckets = new BucketsApi();
- dynamic token = await OAuthController.GetInternalAsync();
+ dynamic token = await OAuthController.GetInternalAsync(_configuration);
buckets.Configuration.AccessToken = token.access_token;
PostBucketsPayload bucketPayload = new PostBucketsPayload(string.Format("{0}-{1}", ClientId, bucket.bucketKey.ToLower()), null,
PostBucketsPayload.PolicyKeyEnum.Transient);
@@ -111,7 +115,7 @@ namespace forgeSample.Controllers
// get the bucket...
- dynamic oauth = await OAuthController.GetInternalAsync();
+ dynamic oauth = await OAuthController.GetInternalAsync(_configuration);
ObjectsApi objects = new ObjectsApi();
objects.Configuration.AccessToken = oauth.access_token;
diff --git a/Backend/appsettings.Development.json b/Backend/appsettings.Development.json
index f99be74..1a61e16 100644
--- a/Backend/appsettings.Development.json
+++ b/Backend/appsettings.Development.json
@@ -82,5 +82,9 @@
"Account": "FMiVG4sIeDFmAUc/8Hn/kw==", //巨蛋
"Password": "4+ussQ8rHohjPWpNvoujJQ==" //巨蛋
}
+ },
+ "Forge": {
+ "CLIENT_ID": "kDOSvxcoLPCFKTncWV9GxgFcGFMkUz9W",
+ "CLIENT_SECRET": "peaXsHcAorGNdZYd"
}
}
diff --git a/Backend/appsettings.json b/Backend/appsettings.json
index d276a82..512cbeb 100644
--- a/Backend/appsettings.json
+++ b/Backend/appsettings.json
@@ -64,5 +64,9 @@
"Account": "FMiVG4sIeDFmAUc/8Hn/kw==", //巨蛋
"Password": "4+ussQ8rHohjPWpNvoujJQ==" //巨蛋
}
+ },
+ "Forge": {
+ "CLIENT_ID": "kDOSvxcoLPCFKTncWV9GxgFcGFMkUz9W",
+ "CLIENT_SECRET": "peaXsHcAorGNdZYd"
}
}
diff --git a/Backend/wwwroot/forgeDemo.html b/Backend/wwwroot/forgeDemo.html
index 2a681f4..8ac57ed 100644
--- a/Backend/wwwroot/forgeDemo.html
+++ b/Backend/wwwroot/forgeDemo.html
@@ -287,8 +287,8 @@
//2023-05 三菱 dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6em80emd1eWFsaGpybDVvODF2YTM5cGtkZ3I4MndhbXEtbWl6dWJpc2hpLyVFMyU4MCU5MCVFNSU4RiVCMCVFNSU4QyU5NyVFNCVCOCVBRCVFOCU4RiVCMSVFNSVBNCVBNyVFNiVBOCU5MyVFMyU4MCU5MUFSQyVFOSU5QiU5OSVFNiVBOCVBMSVFNSVCQyU4RitNRVAlRTYlOEIlODYlRTclQjMlQkIlRTclQjUlQjFfJUU5JTlCJUJCJUU2JUEyJUFGJUU3JUI0JUIwJUU3JUFGJTgwJUU3JTg5JTg4Lm53ZA
//launchViewer("dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6em80emd1eWFsaGpybDVvODF2YTM5cGtkZ3I4MndhbXEtbWl6dWJpc2hpLyVFMyU4MCU5MCVFNSU4RiVCM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CVCNCVFNyVBRSVBMSkwMzE2Lm53ZA");
});
function move1Floor() {
setElevatorSpeed(0.2);