npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@onshape/apikey

v1.0.0

Published

Sample application using API keys

Downloads

33

Readme

Onshape API Key encoding package

Build

Make HTTP requests to Onshape using an API Key.


Getting Started

Please see the node examples for further examples of using this package.

Why API Keys?

API keys are useful for small applications meant for personal use, allowing developers to avoid the overhead of the OAuth workflow. Creating an app is very easy with API keys, as the samples hopefully demonstrate: create an API key with the Developer Portal, set up a function to build your API key header as in the samples, and make your API calls! There's no need to deal with OAuth redirects or things like that.

We've moved over to using API keys for authenticating requests instead of using cookies for several reasons.

  1. Security: Each request is signed with unique headers so that we can be sure it's coming from the right place.
  2. OAuth: The API key system we're now using for HTTP requests is the same process developers follow when building full-blown OAuth applications; there's no longer a disconnect between the two.

Questions and Concerns

If you need information or have a question unanswered in this documentation, feel free to chat with us by sending an email to [email protected] or by checking out the forums.

Working with API Keys

Read the following and you'll be up and running with using API keys in your application:

Instructions
  1. Create and manage your API key pairs from the Developer Portal; note that the secret will only be displayed once! Keep it somewhere safe.

  2. Now that you have a key pair, see below for information on signing your requests to use our API.

Once you have your access key and secret, you will want to avoid giving others access to them since they're tied directly to your personal Onshape account. Think of your API key as a username and password pair. Therefore, you should avoid placing them directly in the code for your application, especially if others might see it. The samples use a separate configuration file that you yourself will need to create that will contain this information, but there are other ways to keep the access key and secret safe, like setting them as environment variables.

Scopes

There are several scopes available for API keys (equivalent to OAuth scopes):

  • "OAuth2Read" - Read non-personal information (documents, parts, etc.)
  • "OAuth2ReadPII" - Read personal information (name, email, etc.)
  • "OAuth2Write" - Create and edit documents / etc.
  • "OAuth2Delete" - Delete documents / etc.
  • "OAuth2Purchase" - Authorize purchases from account
Signing an HTTP Request
var client = require('@onshape/apikey');

var apiKeyDetails = {
    'baseUrl': 'https://cad.onshape.com',
    'accessKey': YOUR_ACCESS_KEY,
    'secretKey': YOUR_SECRET_KEY
};

client(apiKeyDetails).getDocuments({}, function (data) {
    // Process the response data
    })

Some API endpoints return 307 redirects. You must generate an Authorization header for the redirect as well, but please note that the server portion of the URL might be different, the redirect URL may contain query parameters that must be encoded in the Authorization header, etc. Please see the samples for examples.

API keys and OAuth

Our API key workflow differs from our OAuth workflow in one important characteristic: an API key allows a user (specifically, a developer) to make requests, while OAuth allows an application to make requests on behalf of the user. We require the OAuth workflow for apps in the Onshape App Store, so if you develop an app using API keys and want to distribute it through the App Store, you will need to change to OAuth. Please see our OAuth sample apps for examples of how to make OAuth work (onshape/app-bom is a great place to start). The good news is that we've structured API keys to work very similarly to OAuth in the operation of your app. While you will need to build your Authorization header differently (and set up redirects and signins as in the onshape/app-bom sample), the API calls themselves will work the same in both versions, provided that the API key and the OAuth app have the same scopes. An API key with the OAuth2Read and OAuth2Write scopes will have the same access to the same API endpoints as an OAuth application with the OAuth2Read and OAuth2Write scopes, for example. (The only differences are when calling API endpoints relating to the OAuth application itself, since an API key request obviously does not come from an OAuth application.)