# passport-crypt-oauth20

> Passport Strategy for CryPt OAuth2.0 Server

Latest version **1.0.3** (published 2020-05-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install passport-crypt-oauth20
pnpm add passport-crypt-oauth20
yarn add passport-crypt-oauth20
bun add passport-crypt-oauth20
```

## 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.3 |
| Published | 2020-05-06 |
| First published | 2020-05-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sharvan Sharma |
| Maintainers | sharvan-npm-ac-1 |
| Keywords | crypt-oauth20, crypt, oauth, passport, authentication, identity |

## Links

- npm: https://www.npmjs.com/package/passport-crypt-oauth20
- Repository: https://github.com/sharvan-sharma/passport-crypt-oauth20
- Homepage: https://github.com/sharvan-sharma/passport-crypt-oauth20#readme
- Issues: https://github.com/sharvan-sharma/passport-crypt-oauth20/issues
- npm.io page: https://npm.io/package/passport-crypt-oauth20

## Dependencies (1)

- [passport-oauth2](https://npm.io/package/passport-oauth2.md) 1.x.x

## Alternatives

- [@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
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-05-06
- 1.0.2 — 2020-05-03
- 1.0.1 — 2020-05-03
- 1.0.0 — 2020-05-03

## README

# passport-crypt-oauth20

[Passport](http://www.passportjs.org/) strategy for authenticating with [CryPt](https://crypt-oauth.web.app) using the OAuth 2.0 API.

This module lets you authenticate using CryPt in your Node.js applications.

## Install

```
$ npm install passport-crypt-oauth20
```

## Usage

### Create An Application

---

Before using ```passport-crypt-oauth20```, you must register an application with CryPt. If you have not already done so, a new application can be created in the [CryPt Developers Console](https://crypt-oauth.web.app/devconsole). Your application will be issued a client ID and client secret, which need to be provided to the strategy. You will also need to configure a redirect URI which matches the route in your application.

### Configure Strategy

---

The CryPt authentication strategy authenticates users using a CryPt account and OAuth 2.0 tokens. The client ID and secret obtained when creating an application are supplied as options when creating the strategy. The strategy also requires a ```verify``` callback, which receives the access token and optional refresh token, as well as ```profile``` which contains the authenticated user's CryPt profile. The ```verify``` callback must call ```cb``` (done is used as cb in following code snippet) providing a user to complete authentication.

```javascript
const CryPtStrategy = require('passport-crypt-oauth20')

passport.use(new CryPtStrategy({
         clientID: CONSUMER_CLIENT_ID,
         clientSecret: CONSUMER_CLIENT_SECRET,
         callbackURL: 'http://example.com/crypt/oauth/callback',
         scope:'profile'
       },
       function(accessToken, refreshToken, profile, done) {
        User.findOne({cryptId:profile.cryptId},(err,user)=>{
            if(err) throw err
            else if(user){return done(err,user)}
            else{
                User.create({...profile,
                    access_token:accessToken,
                    refersh_token:refreshToken
                },(error,userdoc)=>{
                    return done(error,userdoc)
                })
            }
        })
       }
     ));
```

### Authenticate Requests

---

Use ```passport.authenticate()```, specifying the 'crypt' strategy, to authenticate requests.

For example, as route middleware in an [Express](expressjs.com) application:

```javascript
app.get('/crypt/oauth/login',passport.authenticate('crypt'))

app.get('/crypt/oauth/callback', 
  passport.authenticate('crypt', { failureRedirect: '/loginfail',successRedirect:'/protected' }))

```

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