# wpcom-browser-auth

> Browser authentication logic for the WordPress.com REST API

Latest version **1.0.0** (published 2014-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install wpcom-browser-auth
pnpm add wpcom-browser-auth
yarn add wpcom-browser-auth
bun add wpcom-browser-auth
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-11-04 |
| First published | 2014-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Nathan Rajlich |
| Maintainers | tootallnate |
| Keywords | wpcom, rest, api, auth, authentication, token, oauth, browser, wordpress |

## Links

- npm: https://www.npmjs.com/package/wpcom-browser-auth
- Repository: https://github.com/Automattic/wpcom-browser-auth
- Issues: https://github.com/Automattic/wpcom-browser-auth/issues
- npm.io page: https://npm.io/package/wpcom-browser-auth

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2014-11-04

## README

# wpcom-browser-auth

**Browser authentication logic for the WordPress.com REST API**


This module provides authentication logic for web browsers to authenticate
against the WordPress.com REST API.

You must create a WordPress.com Application, with the "Native" app type.
Then you may pass the `client_id` of your application to the `redirect()`
function.

In your Redirect URL page, you invoke the `response()` function to get
the parsed access token (or error object if the user refused access),
with which you can execute API calls against the REST API.


### Installation

Install `wpcom-browser-auth` using `npm`:

``` bash
$ npm install wpcom-browser-auth
```


### Example

``` html
<html>
  <body>
    <script src="wpcom-browser-auth.js"></script>
    <script>
      var auth = wpcomBrowserAuth.response();
      if (auth) {
        // invoked as part of the Redirect URL
        if (auth.error) {
          // user denied WordPress.com access
        } else {
          // user granted access to WordPress.com
          var wpcom = new WPCOM(auth.access_token);
          var site = wpcom.site(auth.site_id);
        }
      } else {
        // no auth token information, redirect to OAuth page
        wpcomBrowserAuth.redirect(client_id);
      }
    </script>
  </body>
</html>
```

See the [example](./example/index.html) file for a more complete example.

---
_Source: https://npm.io/package/wpcom-browser-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
