Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 86d68ec

Browse files
committedOct 22, 2020
remove Hapi plugin
1 parent 866e8cb commit 86d68ec

File tree

5 files changed

+1
-1174
lines changed

5 files changed

+1
-1174
lines changed
 

‎API.md

-144
Original file line numberDiff line numberDiff line change
@@ -329,150 +329,6 @@ Hawk client from authenticating the requests.You can read more about the why and
329329
[article](http://www.html5rocks.com/en/tutorials/cors/#toc-adding-cors-support-to-the-server)
330330

331331

332-
## hapi Plugin
333-
334-
**hawk** includes an authentication plugin for **hapi** which registers two authentication schemes.
335-
336-
### hawk Strategy
337-
338-
The scheme supports payload authentication. The scheme requires the following options:
339-
340-
- `getCredentialsFunc` - credential lookup function with the signature `[async] function(id)` where:
341-
- `id` - the Hawk credentials identifier.
342-
- _throws_ an internal error.
343-
- _returns_ `{ credentials }` object where:
344-
- `credentials` a credentials object passed back to the application in `request.auth.credentials`. Set to be `null` or `undefined` to
345-
indicate unknown credentials (which is not considered an error state).
346-
- `hawk` - optional protocol options passed to `Hawk.server.authenticate()`.
347-
348-
```js
349-
const Hapi = require('@hapi/hapi');
350-
const Hawk = require('@hapi/hawk');
351-
352-
const credentials = {
353-
d74s3nz2873n: {
354-
key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
355-
algorithm: 'sha256'
356-
}
357-
};
358-
359-
const getCredentialsFunc = function (id) {
360-
361-
return credentials[id];
362-
};
363-
364-
const start = async () => {
365-
366-
const server = Hapi.server({ port: 4000 });
367-
368-
await server.register(Hawk);
369-
370-
server.auth.strategy('default', 'hawk', { getCredentialsFunc });
371-
server.auth.default('default');
372-
373-
server.route({
374-
method: 'GET',
375-
path: '/',
376-
handler: function (request, h) {
377-
378-
return 'welcome';
379-
}
380-
});
381-
382-
await server.start();
383-
384-
console.log('Server started listening on %s', server.info.uri);
385-
};
386-
387-
start();
388-
389-
// Ensure process exits on unhandled rejection
390-
391-
process.on('unhandledRejection', (err) => {
392-
393-
throw err;
394-
});
395-
396-
```
397-
398-
### bewit Strategy
399-
400-
The scheme can only be used with 'GET' requests and requires the following options:
401-
402-
- `getCredentialsFunc` - credential lookup function with the signature `async function(id)` where:
403-
- `id` - the Hawk credentials identifier.
404-
- _throws_ an internal error.
405-
- _returns_ `{ credentials }` object where:
406-
- `credentials` a credentials object passed back to the application in `request.auth.credentials`. Set to be `null` or `undefined` to
407-
indicate unknown credentials (which is not considered an error state).
408-
- `hawk` - optional protocol options passed to `Hawk.server.authenticateBewit()`.
409-
410-
```js
411-
const Hapi = require('@hapi/hapi');
412-
const Hawk = require('@hapi/hawk');
413-
414-
const credentials = {
415-
d74s3nz2873n: {
416-
key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
417-
algorithm: 'sha256'
418-
}
419-
};
420-
421-
const getCredentialsFunc = function (id) {
422-
423-
return credentials[id];
424-
};
425-
426-
const start = async () => {
427-
428-
const server = Hapi.server({ port: 4000 });
429-
430-
await server.register(Hawk);
431-
432-
server.auth.strategy('default', 'bewit', { getCredentialsFunc });
433-
server.auth.default('default');
434-
435-
server.route({
436-
method: 'GET',
437-
path: '/',
438-
handler: function (request, h) {
439-
440-
return 'welcome';
441-
}
442-
});
443-
444-
await server.start();
445-
446-
console.log('Server started listening on %s', server.info.uri);
447-
};
448-
449-
start();
450-
451-
// Ensure process exits on unhandled rejection
452-
453-
process.on('unhandledRejection', (err) => {
454-
455-
throw err;
456-
});
457-
```
458-
459-
To send an authenticated Bewit request, the URI must contain the `'bewit'` query parameter which can be generated using the Hawk module:
460-
461-
```js
462-
const Hawk = require('@hapi/hawk');
463-
464-
const credentials = {
465-
id: 'd74s3nz2873n',
466-
key: 'werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn',
467-
algorithm: 'sha256'
468-
};
469-
470-
let uri = 'http://example.com:8080/endpoint';
471-
const bewit = Hawk.client.getBewit(uri, { credentials: credentials, ttlSec: 60 });
472-
uri += '?bewit=' + bewit;
473-
```
474-
475-
476332
# Single URI Authorization
477333

478334
There are cases in which limited and short-term access to a protected resource is granted to a third party which does not

‎lib/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ exports.crypto = require('./crypto');
1111

1212
exports.utils = require('./utils');
1313

14-
exports.plugin = require('./plugin');
15-
1614
exports.uri = {
1715
authenticate: exports.server.authenticateBewit,
1816
getBewit: exports.client.getBewit

‎lib/plugin.js

-134
This file was deleted.

‎package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
"hawk"
1515
],
1616
"dependencies": {
17-
"@hapi/hoek": "9.x.x",
1817
"@hapi/b64": "5.x.x",
1918
"@hapi/boom": "9.x.x",
2019
"@hapi/cryptiles": "5.x.x",
20+
"@hapi/hoek": "9.x.x",
2121
"@hapi/sntp": "4.x.x"
2222
},
2323
"devDependencies": {
2424
"@hapi/code": "8.x.x",
25-
"@hapi/hapi": "19.x.x",
2625
"@hapi/lab": "22.x.x"
2726
},
2827
"scripts": {

‎test/plugin.js

-892
This file was deleted.

3 commit comments

Comments
 (3)

community-tc-integration[bot] commented on Oct 22, 2020

@community-tc-integration[bot]
Uh oh! Looks like an error! Details

Taskcluster-GitHub attempted to create a task for this event with the following scopes:

[
  "assume:repo:github.com/mozilla/hawk:branch:issue272",
  "queue:route:statuses",
  "queue:scheduler-id:taskcluster-github"
]

The expansion of these scopes is not sufficient to create the task, leading to the following:

Client ID static/taskcluster/github does not have sufficient scopes and is missing the following scopes:

{
  "AnyOf": [
    "queue:create-task:highest:proj-taskcluster/ci",
    "queue:create-task:very-high:proj-taskcluster/ci",
    "queue:create-task:high:proj-taskcluster/ci",
    "queue:create-task:medium:proj-taskcluster/ci",
    "queue:create-task:low:proj-taskcluster/ci",
    "queue:create-task:very-low:proj-taskcluster/ci",
    "queue:create-task:lowest:proj-taskcluster/ci"
  ]
}

This request requires the client to satisfy the following scope expression:

{
  "AllOf": [
    "queue:route:statuses",
    "queue:scheduler-id:taskcluster-github",
    {
      "AnyOf": [
        "queue:create-task:highest:proj-taskcluster/ci",
        "queue:create-task:very-high:proj-taskcluster/ci",
        "queue:create-task:high:proj-taskcluster/ci",
        "queue:create-task:medium:proj-taskcluster/ci",
        "queue:create-task:low:proj-taskcluster/ci",
        "queue:create-task:very-low:proj-taskcluster/ci",
        "queue:create-task:lowest:proj-taskcluster/ci"
      ]
    }
  ]
}

  • method: createTask
  • errorCode: InsufficientScopes
  • statusCode: 403
  • time: 2020-10-22T22:28:28.517Z

community-tc-integration[bot] commented on Oct 22, 2020

@community-tc-integration[bot]
Uh oh! Looks like an error! Details

Taskcluster-GitHub attempted to create a task for this event with the following scopes:

[
  "assume:repo:github.com/mozilla/hawk:pull-request",
  "queue:route:statuses",
  "queue:scheduler-id:taskcluster-github"
]

The expansion of these scopes is not sufficient to create the task, leading to the following:

Client ID static/taskcluster/github does not have sufficient scopes and is missing the following scopes:

{
  "AnyOf": [
    "queue:create-task:highest:proj-taskcluster/ci",
    "queue:create-task:very-high:proj-taskcluster/ci",
    "queue:create-task:high:proj-taskcluster/ci",
    "queue:create-task:medium:proj-taskcluster/ci",
    "queue:create-task:low:proj-taskcluster/ci",
    "queue:create-task:very-low:proj-taskcluster/ci",
    "queue:create-task:lowest:proj-taskcluster/ci"
  ]
}

This request requires the client to satisfy the following scope expression:

{
  "AllOf": [
    "queue:route:statuses",
    "queue:scheduler-id:taskcluster-github",
    {
      "AnyOf": [
        "queue:create-task:highest:proj-taskcluster/ci",
        "queue:create-task:very-high:proj-taskcluster/ci",
        "queue:create-task:high:proj-taskcluster/ci",
        "queue:create-task:medium:proj-taskcluster/ci",
        "queue:create-task:low:proj-taskcluster/ci",
        "queue:create-task:very-low:proj-taskcluster/ci",
        "queue:create-task:lowest:proj-taskcluster/ci"
      ]
    }
  ]
}

  • method: createTask
  • errorCode: InsufficientScopes
  • statusCode: 403
  • time: 2020-10-22T22:29:18.310Z

community-tc-integration[bot] commented on Oct 22, 2020

@community-tc-integration[bot]
Uh oh! Looks like an error! Details

Taskcluster-GitHub attempted to create a task for this event with the following scopes:

[
  "assume:repo:github.com/mozilla/hawk:pull-request",
  "queue:route:statuses",
  "queue:scheduler-id:taskcluster-github"
]

The expansion of these scopes is not sufficient to create the task, leading to the following:

Client ID static/taskcluster/github does not have sufficient scopes and is missing the following scopes:

{
  "AnyOf": [
    "queue:create-task:highest:proj-taskcluster/ci",
    "queue:create-task:very-high:proj-taskcluster/ci",
    "queue:create-task:high:proj-taskcluster/ci",
    "queue:create-task:medium:proj-taskcluster/ci",
    "queue:create-task:low:proj-taskcluster/ci",
    "queue:create-task:very-low:proj-taskcluster/ci",
    "queue:create-task:lowest:proj-taskcluster/ci"
  ]
}

This request requires the client to satisfy the following scope expression:

{
  "AllOf": [
    "queue:route:statuses",
    "queue:scheduler-id:taskcluster-github",
    {
      "AnyOf": [
        "queue:create-task:highest:proj-taskcluster/ci",
        "queue:create-task:very-high:proj-taskcluster/ci",
        "queue:create-task:high:proj-taskcluster/ci",
        "queue:create-task:medium:proj-taskcluster/ci",
        "queue:create-task:low:proj-taskcluster/ci",
        "queue:create-task:very-low:proj-taskcluster/ci",
        "queue:create-task:lowest:proj-taskcluster/ci"
      ]
    }
  ]
}

  • method: createTask
  • errorCode: InsufficientScopes
  • statusCode: 403
  • time: 2020-10-22T22:29:49.521Z
This repository has been archived.