10 Mar 2023

Generating Access Tokens and Model URNs

Sometimes you may stumble across an interesting code snippet related to the Viewer SDK (for example, on Stack Overflow or Codepen.io) that requires you to plug in your own access token and model URN. Here's a quick tip on how to get these:

Visual Studio Code

If you're developing with Visual Studio Code, and you aren't using our Autodesk Platform Services extension yet, I'd suggest that you give it a try. The extension gives you access to APS services and data, incl. the ability to browse OSS buckets and objects, uploading and translating designs using the Model Derivative service, etc.

Here's how you can use the extension to quickly generate an access token and a model URN:

  • If you don't have the extension yet, follow the instructions in the Installation section to install and configure it
  • If you don't have any models ready for viewing yet, follow the instructions in the Buckets & Derivatives View section to upload and convert one
  • Open the Command Palette, find the command called Authentication: Generate Access Token, and execute it
  • You'll be prompted for a list of scopes for the new token; it's a good practice to limit the capabilities of tokens as much as possible, so specify just a single scope called viewables:read that will only allow the token to access 2D and 3D designs from the Model Derivative service
  • A popup dialog will appear in the bottom-right corner showing the newly generated token; use the Copy Token to Clipboard button to copy it to clipboard, and paste the token in your code snippet

Generate access token

  • In the BUCKETS & DERIVATIVES tree view, select the model you're interested in using, right-click it, use the Copy Object URN to Clipboard menu item, and paste the URN to your code snippet

Get model URN

And that's it!

Try it out

Once you have your access token and model URN ready, try plugging these into the codepen below:

Related Article