Hi,
I have started creating free account to try auth0.
The getting start sample showing the basic Hapi Integration.
Do you have a sample of How to Integrate into (Hapi + Glue) ?
I have an existing code in manifest.json
{
"registrations" :
{
"plugin" : {
"register" : "hapi-auth-basic"
}
},
{
"plugin" : {
"register" : "hapi-auth-cookie"
}
},
{
"plugin" : {
"register" : "../config/routes/dir.js"
},
"options" : {
"select" : "api" ]
}
}
]
}
hapi component (dir.js)
var Inert = require('inert');
// var Path = require('path');
exports.register = function(server, options, next) {
server.register(Inert, () => {});
server.route({
method: 'GET',
path: '/{File*}',
config: {
description: 'Return files in the folder',
tags: 'api2'], // ADD THIS TAG
handler: {
directory: {
path: 'assets', // Path.join(__dirname, 'tools'),
listing: true
}
},
auth: false
}
});
next();
};
exports.register.attributes = {
name: 'tools'
};
This is in my package.json
"dependencies": {
"babel-core": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"bell": "^8.7.0",
"blipp": "^2.3.0",
"glue": "^4.1.0",
"hapi": "^16.1.1",
"hapi-api-version": "^1.3.0",
"hapi-auth-basic": "^4.2.0",
"hapi-auth-cookie": "^7.0.0",
"hapi-auth-jwt": "^4.0.0",
"hapi-auth-jwt2": "^7.2.4",
"hapi-swagger": "^7.7.0",
"hapi-swaggered": "^2.9.0",
"hapi-swaggered-ui": "^2.6.0",
"inert": "^4.2.0",
"jwks-rsa": "^1.1.1",
"package": "^1.0.1",
"rejoice": "^4.0.0",
"rekuire": "^0.1.9",
"swaggerize-hapi": "^2.0.1",
"uuid": "^3.0.1",
"vision": "^4.1.1"
}
Edit:
Hi,
I have been working on other project and now back to this task again.
I can’t navigate to the private link, Unauthorized.
Can you tell me what I have done wrong ?
Thanks.
I have download the sample project running with node + hapi.
I have started at http://localhost:3001/api/private.
I am copying the sample code c# using RestClient Request Bearer Token.
It was successful.
but when I am calling the local host with the sample code c#
calling the http://localhost:3001/api/private
{"statusCode":401,"error":"Unauthorized","message":"Invalid token","attributes":{"error":"Invalid token"}}
- I don’t think I have done it right.
- I have went to https://manage.auth0.com/#/apis
- Create API
- Name: MyApi
- Identifier: http://localhost:3001/api/private
- Create
- I am clicking on Scopes Tab then add name read:messages
- Navigate to “Non Interactive Client”
- Make sure it is Authorized
- and the Scopes, read:messages is checked.
- Then click on test.
- Go to Section: Sending the token to the API
- Select c#
- Copy the code
- then add to the code
Console.WriteLine(response);
if I try from c# code with
url: http://localhost:3001/api/public
{"message":"Hello from a public endpoint! You don't need to be authenticated to see this."}
url: http://localhost:3001/api/private
{"statusCode":401,"error":"Unauthorized","message":"Invalid token","attributes":{"error":"Invalid token"}}