{"id":25838513,"url":"https://github.com/salesflare/hapi-auth-bearer-simple","last_synced_at":"2025-03-01T03:49:46.686Z","repository":{"id":23443288,"uuid":"26806762","full_name":"Salesflare/hapi-auth-bearer-simple","owner":"Salesflare","description":"Hapi authentication plugin for bearer token validation","archived":false,"fork":false,"pushed_at":"2019-03-27T10:56:52.000Z","size":316,"stargazers_count":16,"open_issues_count":4,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-12T22:16:18.533Z","etag":null,"topics":["authentication","bearer","hapi","javascript","plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Salesflare.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-18T11:45:08.000Z","updated_at":"2020-06-25T07:17:43.000Z","dependencies_parsed_at":"2022-08-17T20:45:19.910Z","dependency_job_id":null,"html_url":"https://github.com/Salesflare/hapi-auth-bearer-simple","commit_stats":null,"previous_names":["salesflare/hapi-auth-bearer-plugin"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-auth-bearer-simple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-auth-bearer-simple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-auth-bearer-simple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salesflare%2Fhapi-auth-bearer-simple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Salesflare","download_url":"https://codeload.github.com/Salesflare/hapi-auth-bearer-simple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241313169,"owners_count":19942418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","bearer","hapi","javascript","plugin"],"created_at":"2025-03-01T03:49:46.081Z","updated_at":"2025-03-01T03:49:46.674Z","avatar_url":"https://github.com/Salesflare.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/Salesflare/hapi-auth-bearer-simple.svg?branch=master)](https://travis-ci.org/Salesflare/hapi-auth-bearer-simple)\n[![dep](https://david-dm.org/salesflare/hapi-auth-bearer-simple.svg)](https://david-dm.org/salesflare/hapi-auth-bearer-simple)\n[![dev](https://david-dm.org/salesflare/hapi-auth-bearer-simple/dev-status.svg)](https://david-dm.org/salesflare/hapi-auth-bearer-simple?type=dev)\n[![peer](https://david-dm.org/salesflare/hapi-auth-bearer-simple/peer-status.svg)](https://david-dm.org/salesflare/hapi-auth-bearer-simple?type=peer)\n[![Code Climate](https://codeclimate.com/github/Salesflare/hapi-auth-bearer-simple/badges/gpa.svg)](https://codeclimate.com/github/Salesflare/hapi-auth-bearer-simple)\n\n# Hapi authentication plugin\n\n\u003e [**hapi**](https://github.com/hapijs/hapi) Bearer Token Authentication Scheme\n\n## What\n\nThe plugin requires validating a token passed in by the bearer authorization header or via the `access_token` query param. The validation function is something you have to provide to the plugin.\n\n## How\n\n```javascript\nvar validateFunction = function (token, callback) {\n\n    // Use a real strategy here to check if the token is valid\n    if (token === 'abc456789') {\n        callback(null, true, userCredentials);\n    }\n    else {\n        callback(null, false, userCredentials);\n    }\n};\n\nserver.register(require('hapi-auth-bearer-simple'), function (err) {\n\n    if (err) {\n        throw err;\n    }\n\n    server.auth.strategy('bearer', 'bearerAuth', {\n        validateFunction: validateFunction\n    });\n\n    // Add a standard route here as example\n    server.route({\n        method: 'GET',\n        path: '/',\n        handler: function (request, reply) {\n\n            reply({ success: true });\n        },\n        config: {\n            auth: {\n                strategy: 'bearer',\n                scope: 'user' // or [ 'user', 'admin' ]\n            }\n        }\n    });\n\n    server.start(function (err) {\n\n        if (err) {\n            throw err;\n        }\n\n        server.log([],'Server started at: ' + server.info.uri);\n    });\n});\n```\n\n- `validateFunction` - (required) a token lookup and validation function with the signature `function (token, callback)`\n    - `token` - the auth token received from the client.\n    - `callback` - a callback function with the signature `function (err, isValid, credentials)` where:\n        - `err` - any error.\n        - `isValid` - `true` if both the username was found and the password matched, otherwise `false`.\n        - `credentials` - an object passed back to the plugin and which will become available in the `request`object as `request.auth.credentials`. Normally credentials are only included when `isValid`is `true`.\n- `exposeRequest` - (optional / advanced) If set to `true` the `validateFunction`'s `this` will be set to the `request`. This can be usefull if you have plugins that expose certain functions/objects on the `request` object and you want to use them in your `validateFunction`.\n\n## Notes\n\n- 100% code coverage!\n- You can chain strategies see [](http://hapijs.com/api#serverauthschemename-scheme).\n- If you have any problems and/or questions make a new [**issue**](https://github.com/Salesflare/hapi-auth-bearer-simple/issues).\n- If you want to contribute feel free to fork and add a pull request or again make an [**issue**](https://github.com/Salesflare/hapi-auth-bearer-simple/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalesflare%2Fhapi-auth-bearer-simple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalesflare%2Fhapi-auth-bearer-simple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalesflare%2Fhapi-auth-bearer-simple/lists"}