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

oauthic-google

v0.1.1

Published

Yet another beautiful wrapped mikeal/request with OAuth 2.0 feature for Google APIs.

Downloads

8

Readme

OAuthic Google

Build Status Coverage Status Dependency Status NPM version

Yet another beautiful wrapped mikeal/request with OAuth 2.0 feature for Google APIs.

Install

npm install oauthic-google

Quick-start

Authorize:

require('oauthic-google').client({
    clientId: 'q298ajhzxkkp019cjzkoq01'
  , clientSecret: '228bnzokjpasiodufc'
  , redirectUri: 'https://my.server.com/callback'
  })
  .credentical(code, function (err, credentical, userInfo) {
    // ...
  })

Request:

var client = require('oauthic-google').client({
    clientId: 'q298ajhzxkkp019cjzkoq01'
  , clientSecret: '228bnzokjpasiodufc'
  })
  .token(accessToken, expiresAt)
  .refresh(refreshToken, function (token, expiresAt, next) {
    // saveToDb(token)
    return next()
  })
  .expired(function (token) {
    // log(token + ' has expired and could not be refreshed.')
  })

client.get('/mirror/v1/timeline', function (err, res, timeline) {
  // ...
})

oauthic.client(clientInfo)

Create a new client instance.

Arguments:

  • clientInfo Object - Client informations
    • clientId String - App Key
    • clientScrect String - App Secret
    • callbackUri String - URL to be redirected to by the provider.

Returns:

  • oauthic.Client - Client instance

Class: oauthic.Client

Client, a wrapped mikeal/request instance.

client.authorize([options])

Build the URL of the authorization page.

Arguments:

  • options - Additional parameters
    • scope String | Array - Additional scopes. Should be an array or a string separated by a space. Defaults to openid profile
    • state String - A parameter that would be in the query string in redirectUri. It's useful in avoiding CSRF attacking
    • prompt String - A space-delimited list of string values that specifies whether to prompts the user for re-authentication and consent. Possible values (see Google's OAuth 2.0 docs for more):
      • none - do not display any authentication or consent pages
      • consent - prompt the user for consent
      • select_account - prompt the user to select a user account
    • display String - Specifies how to display the authentication page. Possible values: page, popup, touch or wap
    • loginHint - Provides the user's unique ID or email if it's known to skip the multi-login selecting page or pre-fill the email box on the sign-in form
    • accessType - Either online (default value) or offline. Should be offline if you want a Refresh Token
    • approvalPrompt - Should be force if you want a Refresh Token

Returns:

  • String - URL of the authorization page

client.credentical(code, callback)

Get Access Token with an Authorization Code and get ready for making a request.

Arguments:

  • code String - Authorization Code
  • callback(err, credentical, userInfo) Function - Callback
    • err Error | null - Error object
    • credentical Object - Token informations
      • accessToken String - Access Token
      • expiresAt Date - The time when Access Token expires
      • refreshToken String - Refresh Token
    • userInfo Object - Additional user informations
      • id String - The user's unique ID
      • picture String - The URL of user's avatar picture (requires profile scope)
      • name String - The user's display name (requires profile scope)
      • gender String - The user's gender (requires profile scope)
      • locale String - The user's language (requires profile scope)
      • email String The user's email address (requires email scope)
      • _json - Object - Original JSON responsed

Returns:

  • oauthic.Client - Client instance

client.token(accessToken[, expiresAt])

Set the Access Token.

Arguments:

  • accessToken String - Access Token
  • expiresAt Date | Number - Optional. The time when Access Token expires

Returns:

  • oauthic.Client - Client instance

client.refresh(refreshToken, onRefreshed)

client.expired(onExpired)

Registers a handler that would be called when the Access Token is expired and could not be refreshed.

Arguments:

  • onExpired(token) Function - Handler function
    • token String - The expired Access Token

client.get(uri[, options][, callback]), client.post(uri[, options][, callback])

Wrapped methods from mikeal/request. General parameters (e.g. access token) is added. URL could be written in short form, e.g. /mirror/v1/timeline for https://www.googleapi.com/mirror/v1/timeline.

Errors:

  • oauthic.TokenExpiredError - The Access Token is expired and could not be refreshed

client.accessToken

  • String

Returns the current user's Access Token. Useful when you'd prefer building request parameters manually.

oauthic.TokenExpiredError

Occurs when the Access Token is expired and could not be refreshed.

Properties:

  • token String - The expired Access Token

License

(The MIT License)

Copyright (c) 2013 XiNGRZ <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.