Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grant-profile

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grant-profile - npm Package Compare versions

Comparing version 0.0.11 to 1.0.0

38

package.json
{
"name": "grant-profile",
"version": "0.0.11",
"description": "User profile middleware for Grant",
"version": "1.0.0",
"description": "User profile plugin for Grant",
"keywords": [

@@ -25,23 +25,22 @@ "oauth",

"dependencies": {
"qs": "^6.9.1",
"request-compose": "^1.2.1",
"request-oauth": "0.0.3"
"request-compose": "^2.0.0",
"request-oauth": "^1.0.0"
},
"devDependencies": {
"@hapi/hapi": "^18.4.0",
"@hapi/hapi": "^18.4.1",
"@hapi/yar": "^9.2.1",
"coveralls": "^3.0.9",
"coveralls": "^3.0.11",
"express": "^4.17.1",
"express-session": "^1.17.0",
"grant": "^4.6.3",
"istanbul": "1.1.0-alpha.1",
"grant": "^5.0.0",
"koa": "^2.11.0",
"koa-qs": "^2.0.0",
"koa-session": "^5.12.3",
"mocha": "^6.2.2",
"request-cookie": "0.0.2",
"request-logs": "^1.0.3"
"koa-session": "^5.13.1",
"mocha": "^7.1.1",
"nyc": "^15.0.1",
"request-cookie": "^1.0.0",
"request-logs": "^2.0.0"
},
"peerDependencies": {
"grant": ">=4.6.3"
"grant": ">=5.0.0"
},

@@ -51,12 +50,11 @@ "main": "./profile.js",

"config/",
"lib/",
"profile.js",
"LICENSE",
"package.json",
"profile.js",
"README.md"
"README.md",
"package.json"
],
"scripts": {
"test": "npm run test:ci",
"test:ci": "mocha test/ --recursive",
"test:cov": "istanbul cover _mocha -- --recursive"
"test:ci": "npx mocha --recursive",
"test:cov": "npx nyc --reporter=lcov --reporter=text-summary mocha -- --recursive"
},

@@ -63,0 +61,0 @@ "engines": {

exports.express = () => {
return require('./lib/consumer/express')
var request = require('request-compose').extend({
Request: {oauth: require('request-oauth')}
}).client
var profile = require('./config/profile')
var pkg = require('./package.json')
var before = {
arcgis: () => ({qs: {f: 'json'}}),
constantcontact: (data, provider) => ({api_key: provider.key}),
baidu: (data) => ({qs: {access_token: data.access_token}}),
deezer: (data) => ({qs: {access_token: data.access_token}}),
disqus: (data, provider) => ({qs: {api_key: provider.key}}),
dropbox: () => ({method: 'POST'}),
echosign: (data) => ({headers: {'Access-Token': data.access_token}}),
flickr: (data, provider) => ({qs: {method: 'flickr.urls.getUserProfile', api_key: provider.key, format: 'json'}}),
foursquare: (data) => ({qs: {oauth_token: data.access_token}}),
getpocket: (data, provider) => ({json: {consumer_key: provider.key, access_token: data.access_token}}),
instagram: (data, provider) =>
/^\d+$/.test(provider.key)
? {qs: {fields: 'id,account_type,username'}}
: {
url: provider.profile_url || profile.instagram.profile_url_v1,
qs: {access_token: data.access_token}
},
linkedin: (data) => ({headers: {'x-li-format': 'json'}}),
mailchimp: (data) => ({qs: {apikey: data.access_token}}),
meetup: (data) => ({qs: {member_id: 'self'}}),
mixcloud: (data) => ({qs: {access_token: data.access_token}}),
shopify: (data) => ({headers: {'X-Shopify-Access-Token': data.access_token}}),
slack: (data) => ({qs: {token: data.access_token}}),
soundcloud: (data) => ({qs: {oauth_token: data.access_token}}),
stackexchange: (data) => ({qs: {key: data.access_token}}),
stocktwits: (data) => ({qs: {access_token: data.access_token}}),
trello: (data) => ({qs: {key: data.access_token}}),
tumblr: (data) => ({qs: {api_key: data.access_token}}),
vk: (data) => ({qs: {access_token: data.access_token, v: '5.103'}}),
weibo: (data) => ({qs: {access_token: data.access_token}}),
twitter: (data) => ({qs: {user_id: data.raw.user_id}}),
}
exports.koa = () => {
return require('./lib/consumer/koa')
var after = {
// incorrect content-type
arcgis: ({res, body}) => JSON.parse(body),
// JSONP
flickr: ({res, body}) => JSON.parse(/^.*\((.*)\)/.exec(body)[1]),
}
exports.hapi = () => {
return require('./lib/consumer/hapi')
module.exports = () => async ({provider, input, output}) => {
if (provider.response && !provider.response.includes('profile')) {
return {provider, input, output}
}
if (!provider.profile_url && (
!profile[provider.name] || !profile[provider.name].profile_url
)) {
output.profile = {error: 'grant-profile: Not implemented!'}
return {provider, input, output}
}
var options = {
method: 'GET',
url: provider.profile_url || profile[provider.name].profile_url,
headers: {'user-agent': `simov/grant-profile/${pkg.version}`},
}
if (provider.subdomain) {
options.url = options.url.replace('[subdomain]', provider.subdomain)
}
if (provider.oauth === 2) {
options.headers.authorization = `Bearer ${output.access_token}`
}
else if (provider.oauth === 1) {
options.oauth = {
consumer_key: provider.key,
consumer_secret: provider.secret,
token: output.access_token,
token_secret: output.access_secret,
}
}
if (before[provider.name]) {
options = Object.assign(options, before[provider.name](output, provider))
}
var body = await request(options)
.then(({res, body}) =>
after[provider.name]
? after[provider.name]({res, body})
: body
)
output.profile = body
return {provider, input, output}
}
# grant-profile
[![npm-version]][npm] [![travis-ci]][travis] [![coveralls-status]][coveralls]
<!-- [![npm-version]][npm] [![travis-ci]][travis] [![coveralls-status]][coveralls] -->
> _User profile middleware for **[Grant]**_
> _User Profile plugin for **[Grant]**_
## Configuration
__NOTE:__ For grant-profile as a middleware for Express, Koa, and Hapi see [v0.x branch][v0]
> **grant-profile accepts your Grant [configuration][grant-config]**
In addition to that a `profile_url` key can be specified for any provider. This can be used for custom providers, or simply to override the `profile_url` for existing one. Note that in some cases a custom logic might be needed for the internal HTTP [client].
## Use
> *Not all of the supported providers in Grant are tested here, or have the correct profile URL set. Check out the [configuration][profile-config] for current status.*
Pass your [Grant configuration] as the `config` key, and the grant-profile plugin as item in the `extend` array:
## Middlewares
For Express and Koa grant-profile needs to be mounted after Grant, and before any of the callback URLs defined in your Grant configuration.
Additionally a `profile` key is attached to your [session] containing the user profile data.
## Express
```js
var express = require('express')
var session = require('express-session')
var grant = require('grant-express') // or require('grant').express()
var profile = require('grant-profile').express()
var config = require('./config.json')
express()
.use(session({secret: 'grant', saveUninitialized: true, resave: true}))
.use(grant(config))
.use(profile(config))
.use('/hi', (req, res) => {
var {response, profile} = req.session.grant
res.end(JSON.stringify({response, profile}, null, 2))
})
.listen(3000)
```
## Koa
```js
var Koa = require('koa')
var session = require('koa-session')
var grant = require('grant-koa') // or require('grant').koa()
var profile = require('grant-profile').koa()
var config = require('./config.json')
var app = new Koa()
app.keys = ['grant']
app.use(session(app))
app.use(grant(config))
app.use(profile(config))
app.use((ctx, next) => {
if (ctx.path === '/hi') {
var {response, profile} = ctx.session.grant
ctx.body = JSON.stringify({response, profile}, null, 2)
}
var Grant = require('grant-express|koa|hapi')
var grant = Grant({
config: require('./config.json'),
extend: [require('grant-profile')]
})
app.listen(3000)
```
## Hapi
## Configuration
```js
var Hapi = require('hapi')
var yar = require('yar')
var grant = require('grant-hapi') // or require('grant').hapi()
var profile = require('grant-profile').hapi()
var config = require('./config.json')
Grant Profile supports one additional configuration option called `profile_url`, that can be set for any provider.
var server = new Hapi.Server({host: 'localhost', port: 3000})
The `profile_url` have to be set for [custom providers].
server.route({method: 'GET', path: '/hi', handler: (req, res) => {
var {response, profile} = req.yar.get('grant')
return res.response(JSON.stringify({response, profile}, null, 2))
.header('content-type', 'text/plain')
}})
It also can be used to override or set the `profile_url` for existing providers. Note that in some cases a custom logic might be needed for the internal [HTTP client].
server.register([
{plugin: grant(), options: config},
{plugin: profile(), options: config},
{plugin: yar, options: {cookieOptions: {password: '01234567890123456789012345678912', isSecure: false}}},
])
.then(() => server.start())
```
> Not all of the supported providers in Grant are tested here, or have the correct profile URL set. Check out the [configuration][profile-config] for current status.
## Example
## Response Data
> _Used in the above examples._
Additional `profile` key will be added to your [response data] containing the user profile.
```json
{
"defaults": {
"protocol": "http",
"host": "localhost:3000",
"transport": "session",
"state": true,
"nonce": true,
"callback": "/hi"
},
"google": {"key": "..", "secret": "..", "scope": ["openid", "profile", "email"]},
"twitter": {"key": "..", "secret": ".."}
}
```

@@ -118,5 +47,8 @@ [npm-version]: https://img.shields.io/npm/v/grant-profile.svg?style=flat-square (NPM Version)

[grant]: https://github.com/simov/grant
[grant-config]: https://github.com/simov/grant#configuration
[session]: https://github.com/simov/grant#session
[grant configuration]: https://github.com/simov/grant#configuration
[custom providers]: https://github.com/simov/grant#misc-custom-providers
[response data]: https://github.com/simov/grant#callback-data
[v0]: https://github.com/simov/grant-profile/tree/v0
[profile-config]: https://github.com/simov/grant-profile/blob/master/config/profile.json
[client]: https://github.com/simov/grant-profile/blob/master/lib/client.js
[http client]: https://github.com/simov/grant-profile/blob/master/profile.js
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc