kidtronnix / hapi-dash

Boilerplate Hapi Web and API Server Example, with frontend dashboard.
hapi-dash.smaxwellstewart.com
MIT License
113 stars 19 forks source link

The core cred #5

Closed abhay-github closed 10 years ago

abhay-github commented 10 years ago

A cool project.

Can you please tell what is the credentials for core? Or how do i simply change it to something else? somewhere here in config.js? "coreCreds": { "id": "core", "key": "9TKUwfKHIkNbF9XbGdDudA3fiXzxJg4tHATYJrr16vMENNyX9UUvbNkeeRRxQHC9", "algorithm": "sha256" }

Thanks. I am already in process to build an app with this :+1:

kidtronnix commented 10 years ago

Hi @abhay-github. Yes you can change the core creds by changing them coreCreds in config.js.

If you change the key field, you can change the authentication password.

Here is an example hawk auth request:

var Request = require('request');
var Hawk = require('hawk');

// Client credentials, find them in config.js, in the `coreCreds` field
var credentials = {
    id: 'core',
    key: '9TKUwfKHIkNbF9XbGdDudA3fiXzxJg4tHATYJrr16vMENNyX9UUvbNkeeRRxQHC9',
    algorithm: 'sha256'
}

// Request options

var requestOptions = {
    uri: 'http://localhost:3000/api/user',
    method: 'GET',
    headers: {}
};

// Generate Authorization request header

var header = Hawk.client.header('http://localhost:3000/api/user', 'GET', { credentials: credentials, ext: 'some-app-data' });
requestOptions.headers.Authorization = header.field;

// Send authenticated request

Request(requestOptions, function (error, response, body) {

    // Output results
    console.log(body);
});