9 Feb 2023

Scoped Tokens are Here !


Tokens are the core of Forge/APS platform's access control mechanism.  

Tokens act like a temporary password and grant access to sensitive data and resources, only to authorized users, while keeping the system secure.

Today, we are introducing "Scoped Tokens"



Unlike traditional tokens, "Scoped Tokens" are a token that embeds a list of URNs, which restrict what Forge Viewer (now APS) is allowed to view.  

When the Forge Viewer wants to read SVF2 derivative files from OSS (Forge Buckets), the OSS permission system decides if the token has access or not.  

If yes.... then the Viewer will load the 2D/3D model

if no....   then the Viewer is blocked.



The list of URNs, is specified at the time of issuance of a token, and it can’t be changed later.

See our API documentation page, under oAuth, for more details:

scoped tokens api page




Let's go through an example of how to create a scoped token.

First, we create a token as before, but instead of 'read:data' as the scope, we will specify a URN as the scope.


Start with a URN of a 3D Model (or 2D).  The URN has SVF2 derivative files sitting on a Forge OSS bucket and I want to "secure" this 3D model.

Here is the URN...



If we "base64 decode" this URN, then it reveals the filename "rac_basic_sample_project.rvt" and the bucket 'transurban-test/', like this...



Let's generate a Scoped Token of this URN.   Do the following:

> Append "data:read:" to the front of the "base64 decoded" URN.  

Like this string...



Now, generate an Access Token, using this new string, and this CURL command (or Postman):

curl --location --request POST 'https://developer.api.autodesk.com/authentication/v1/authenticate' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=5K...Tc' \
--data-urlencode 'client_secret=By8j....A3' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=data:read:urn:adsk.objects:os.object:transurban-test/rac_basic_sample_project.rvt'

I run this command and it returns this response containing my new Access Token:


NOTE: My example is using v1 oAuth API, but the new v2 oAuth API also works.  I have carefully removed my personal key/secret from the command, so add your own and try the command yourself.


Let's debug the Scoped Access Token, using https://jwt.io 

The JWT report shows our URN scope (circled in RED) ... great !




Now let's try out our new SCOPED_TOKEN with the Viewer.  I run the viewer, and it successfully loads and views my transurban-test/rac_basic_sample_project.rvt 3D model, using this snippet of javascript:

function startViewer( URN ) {
                     accessToken: SCOPED_TOKEN 
                     env: "AutodeskProduction2", 
                     api: 'streamingV2', 
        }, () => {
		  const viewer = new AV.Private.GuiViewer3D( div );
		  AV.Document.load(`urn:${URN}`, (doc) => {
			var viewables = doc.getRoot().getDefaultGeometry();
			viewer.loadDocumentNode(doc, viewables);
... etc


If I try load/view a different model using the same SCOPED_TOKEN, say... transurban-test/stadium_navis_project.nwd then the Viewer fails - it is blocked access to the derivative files.

PERFECT - My URN's are secured !



I can also create a scoped token on a "group of URNs".  I do this by appending URNs together, with a space separator.  

Here's an example of a Scoped Token containing 3 read-only URNs, separated by a 'space'...

data:read:urn:adsk.objects:os.object:transurban-test/rac_basic_sample_project.rvt data:read:urn:adsk.objects:os.object:transurban-test/rac_advanced_sample_project.rvt data:read:urn:adsk.objects:os.object:transurban-test/stadium_navis_project.nwd


And... that's a wrap !



Using the old 'data:read' scope, my viewer could read any URN within in my Forge App.  Now, with Scoped Tokens, I can tighten my security requirements.

Scoped Tokens are a new feature of the APS oAuth and Model Derivative Services and provide a more secure, manageable and compliant way to manage URN access, while avoiding the need to build your own proxy service.


For help, support or questions on Scoped Tokens, feel free to ping me at aps.help@autodesk.com

Book a zoom call with Calendly here: https://calendly.com/michael-beale

Follow me on Twitter: https://twitter.com/micbeale

Related Article