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

@here/olp-sdk-authentication

v2.0.0

Published

Wrapper around the HERE Authentication and Authorization REST API obtaining short-lived access tokens that are used to authenticate requests to HERE services.

Downloads

2,815

Readme

Authentication library

Overview

This repository contains all methods and classes that are required to request an access token for the OAuth authentication.

UserAuth

Description

You can use the UserAuth class instance with your authentication data to get a client access token.

Configure

To create the UserAuth class, pass the configuration object to the constructor.

const auth = new UserAuth(config);

Use with Local Authorization

To use the UserAuth class with local authorization:

  1. Create the UserAuth class instance before instantiating any data sources.

    /**
     * The function gets the access token.
     *
     * You can provide your own implementation or use one from `@here/olp-sdk-authentication`.
     *
     * There are two functions that work for the browser and Node.js.
     * For the browser, `UserAuth` uses `requestToken()` from requestToken.web.ts.
     * For Node.js,`UserAuth` uses `requestToken()` from requestToken.ts.
     *
     * When a function imports a function using `import { requestToken }` from "@here/olp-sdk-authentication"`,
     * the code automatically applies to the corresponding function.
     *
     * The following code is applicable only for Node.js.
     */
    
    import { UserAuth, requestToken } from "@here/olp-sdk-authentication";
    
    const userAuth = new UserAuth({
        env: "here",
        credentials: {
            accessKeyId: "replace-with-your-access-key-id",
            accessKeySecret: "replace-with-your-access-key-secret"
        },
        tokenRequester: requestToken
    });
  2. Get the access token.

    const token: string = await userAuth.getToken();

Use with Credentials Imported from a File (Node.js)

In Node.js, you can use the UserAuth class with credentials imported from the credentials.properties file.

To use the UserAuth class with the credentials imported from the file:

  1. Download your credentials.properties file from the HERE platform website.

  2. Create the UserAuth class instance and set the path to the file with your credentials.

    import {
        UserAuth,
        requestToken,
        loadCredentialsFromFile
    } from "@here/olp-sdk-authentication";
    const credentials = loadCredentialsFromFile(
        "replace-with-your-path-to-credentials.properties"
    );
    const userAuth = new UserAuth({
        credentials,
        tokenRequester: requestToken
    });

    Your credentials.properties file should match the following format:

    here.user.id = "your-here-user-id"
    here.client.id = "your-here-client-id"
    here.access.key.id = "your-here-access-key-id"
    here.access.key.secret = "your-here-access-key-secret"
    here.token.endpoint.url = "your-here-token-endpoint-url"
  3. Get the access token.

    const token: string = await userAuth.getToken();

Generate a Bundle

If you want to have a compiled project, you can use bundle commands. After running each of the following commands in the @here/olp-sdk-authentication folder from the root folder, you get the JavaScript bundled files.

To get bundled files with a source map, run:

npm run bundle

To get a minified version for production, run:

npm run bundle:prod

To get bundled and minified JavaScript files, run:

npm run prepublish-bundle

Use a Bundle from CDN

Add the minified JavaScript file to your HTML and create the userAuth object.

<!DOCTYPE html>
<html lang="en">
    <head>
        <script src="https://unpkg.com/@here/olp-sdk-fetch/bundle.umd.min.js"></script>
        <script src="https://unpkg.com/@here/olp-sdk-authentication/bundle.umd.min.js"></script>
    </head>
    <body>
        <script>
            const userAuth = new UserAuth({
                env: "here",
                credentials: {
                    accessKeyId: "replace-with-your-access-key-id",
                    accessKeySecret: "replace-with-your-access-key-secret"
                },
                tokenRequester: requestToken
            });
            userAuth.getToken().then(token => {
                // your token here
            });
        </script>
    </body>
</html>

LICENSE

Copyright (C) 2019-2023 HERE Europe B.V.

For license details, see the LICENSE.