Unknown authentication strategy "oidc" in okta login - node.js

Here's the full error message,
`Unknown authentication strategy "oidc" Error: Unknown authentication strategy "oidc" at attempt
(/Users/brettwalton/Documents/cfb/cfb/node_modules/passport/lib/middleware/authenticate.js:173:37) at authenticate
(/Users/brettwalton/Documents/cfb/cfb/node_modules/passport/lib/middleware/authenticate.js:349:7) at Layer.handle [as handle_request]
(/Users/brettwalton/Documents/cfb/cfb/node_modules/express/lib/router/layer.js:95:5) at trim_prefix
(/Users/brettwalton/Documents/cfb/cfb/node_modules/express/lib/router/index.js:317:13) at
/Users/brettwalton/Documents/cfb/cfb/node_modules/express/lib/router/index.js:284:7 at Function.process_params
(/Users/brettwalton/Documents/cfb/cfb/node_modules/express/lib/router/index.js:335:12) at next
(/Users/brettwalton/Documents/cfb/cfb/node_modules/express/lib/router/index.js:275:10) at SessionStrategy.strategy.pass
(/Users/brettwalton/Documents/cfb/cfb/node_modules/passport/lib/middleware/authenticate.js:325:9) at SessionStrategy.authenticate
(/Users/brettwalton/Documents/cfb/cfb/node_modules/passport/lib/strategies/session.js:71:10) at attempt
(/Users/brettwalton/Documents/cfb/cfb/node_modules/passport/lib/middleware/authenticate.js:348:16)`
I'm almost positive it has something to do with what i pasted into here, as I'm new to javascript. I edited the code when it wasn't authenticating users.
var oktaClient = new okta.Client({
orgUrl: '{https://dev-232123.oktapreview.com}',
token: 'xxxxxxxxxx'
});
const oidc = new ExpressOIDC({
issuer: "https://{dev-232123.oktapreview.com}/oauth2/default",
client_id: 'xxxxxxxxx',
client_secret: 'xxxxxxxx',
redirect_uri: 'http://localhost:3000/users/callback',
scope: "openid profile",
routes: {
login: {
path: "/users/login"
},
callback: {
path: "/users/callback",
defaultRedirect: "/dashboard"
}
}
});

Just remove /oauth2/default from "https://{dev-232123.oktapreview.com}/oauth2/default", as it is sufficient.
It should be:
issuer: "https://{dev-232123.oktapreview.com}",

Related

Sign in with apple REST api keep getting [Request failed with status code 400] error

I am implementing apple sign in on my website
On my backend(Nodejs), I need to request an authentication token using https://appleid.apple.com/auth/token REST api.
I used Axios and coded as following
export const createSignWithAppleSecret = () => {
const token = jwt.sign({}, signWithApplePrivateKey, {
algorithm: 'ES256',
expiresIn: '1h',
audience: APPLE_DOMAIN,
issuer: APPLE_TEAM_ID,
subject: APPLE_SERVICE_ID,
keyid: APPLE_KEY_ID,
});
return token;
};
export const getAppleToken = async (code: string) =>
axios.post(
'https://appleid.apple.com/auth/token',
qs.stringify({
grant_type: 'authorization_code',
code,
client_secret: createSignWithAppleSecret(),
client_id: APPLE_SERVICE_ID,
redirect_uri: APPLE_REDIRECT_URI,
}),
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}
);
But I am getting Reqest failed with status code 400
Error: Request failed with status code 400\n at createError (/home/ubuntu/sooldamhwa/www/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/home/ubuntu/sooldamhwa/www/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/home/ubuntu/sooldamhwa/www/node_modules/axios/lib/adapters/http.js:260:11)\n at IncomingMessage.emit (events.js:327:22)\n at IncomingMessage.EventEmitter.emit (domain.js:485:12)\n at endReadableNT (_stream_readable.js:1201:12)\n at processTicksAndRejections (internal/process/task_queues.js:84:21)
The api endpoint is correct, and I have configured header as document instructed( https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens)
Could someone please let me know what I did wrong?

Cannot read outlook profile using passport-outlook strategy with nestjs

Always getting the following error while using passport-outlook strategy with scopes scope: ['openid', 'profile', 'offline_access']
In the nest middleware,
consumer.apply(authenticate('outlook', {
session: false,
accessType: 'offline',
scope: ['openid', 'profile', 'offline_access'],
callbackURL: `${callbackUrl}/auth/outlook/login/callback`,
})).forRoutes(
{ path: '/auth/outlook/login', method: RequestMethod.GET },
{ path: '/auth/outlook/login/callback', method: RequestMethod.GET },
)
}
{"error":{"code":"InvalidMsaTicket","message":"ErrorCode:
'PP_E_RPS_CERT_NOT_FOUND'. Message: ' Internal error:
spRPSTicket->ProcessToken failed. Failed to call
CRPSDataCryptImpl::UnpackData: Internal error: Failed to decrypt data.
:Failed to get session key. RecipientId=293577. spCache->GetCacheItem
returns error.:Cert Name: (null). SKI:
45237f1479435b9c4def8b7a1b36edb0105e0546...'","innerError":{"requestId":"4ea03cf1-79f8-421f-a0eb-d5bc6560da6a","date":"2019-07-05T08:44:20"}}}
Did I missed anything in the azure app registration config ?
Do you set up passport.use(new OutlookStrategy({})) in main function with providing there clientID and clientSecret?

Keystone Tutorial: cannot read property 'id' of undefined

I was following the tutorial on starting KeystoneJS from scratch. But when I got to the second part of the tutorial, creating data models, I got this error:
Error thrown for request: /keystone/
TypeError: Cannot read property 'id' of undefined
at IndexRoute (/root/websie/node_modules/keystone/admin/server/routes/index.js:39:16)
at Layer.handle [as handle_request] (/root/websie/node_modules/express/lib/router/layer.js:95:5)
at next (/root/websie/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/root/websie/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/root/websie/node_modules/express/lib/router/layer.js:95:5)
at /root/websie/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/root/websie/node_modules/express/lib/router/index.js:335:12)
at next (/root/websie/node_modules/express/lib/router/index.js:275:10)
at /root/websie/node_modules/keystone/admin/server/app/createDynamicRouter.js:26:3
at Layer.handle [as handle_request] (/root/websie/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/root/websie/node_modules/express/lib/router/index.js:317:13)
at /root/websie/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/root/websie/node_modules/express/lib/router/index.js:335:12)
at next (/root/websie/node_modules/express/lib/router/index.js:275:10)
at handleUploadedFiles (/root/websie/node_modules/keystone/lib/uploads.js:6:54)
at Layer.handle [as handle_request] (/root/websie/node_modules/express/lib/router/layer.js:95:5)
GET /keystone/ 500 8.835 ms
Since I'm new to Keystone JS, I don't quite know if this problem is with the code itself or the database.
Things to consider:
This is run on a linux environment
MongoDB is freshly installed
These are all the files so far:
keystone.js
const keystone = require('keystone')
keystone.init({
'cookie secret': 'SECRET KEY',
'name' : 'theproject',
'user model' : 'User',
'auth' : 'true',
'auto update' : 'true',
});
keystone.import('models');
keystone.start();
User.js:
const keystone = require('keystone');
var User = new keystone.List('User');
User.add({
displayName: { type: String },
password: { type: keystone.Field.Types.Password },
email: { type: keystone.Field.Types.Email, unique: true },
})
User.schema.virtual('canAccessKeystone').get(function () {
return true;
});
User.defaultColumns = 'id, displayName, email';
User.register();
Your User model doesn't have an "id" attribute. So when you set your User.defaultColumns to "id" it doesn't find anything.
All models do however have an "_id" attribute.
I would just remove "id" from your default columns and move forward.
User.defaultColumns = 'displayName, email';
If that doesn't fix it you might be requesting the id elsewhere.

strange behavior jsonwebtoken expired error

I have a Node.js application which uses jsonwebtoken for session management.
However, after the token expired, when I want to access again, I got:
{ TokenExpiredError: jwt expired
at Object.module.exports [as verify] (/home/ubuntu/me-n-you/node_modules/jsonwebtoken/verify.js:126:19)
at auth (/home/ubuntu/me-n-you/app_server/routes/index.js:14:9)
at Layer.handle [as handle_request] (/home/ubuntu/me-n-you/node_modules/express/lib/router/layer.js:95:5)
at next (/home/ubuntu/me-n-you/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/ubuntu/me-n-you/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/ubuntu/me-n-you/node_modules/express/lib/router/layer.js:95:5)
at /home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:335:12)
at next (/home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:174:3)
at router (/home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/home/ubuntu/me-n-you/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:317:13)
at /home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:335:12)
at next (/home/ubuntu/me-n-you/node_modules/express/lib/router/index.js:275:10)
name: 'TokenExpiredError',
message: 'jwt expired',
expiredAt: 2018-05-08T21:14:27.000Z }
I repeat to get the same errors until a very long time then I could access again.
But, I can access if using another device or browser at the same time.
I have no idea how to fix it. Does anyone have any clue on this?
Thanks in advance.
Richard Xu
You can again logged in ,also if you are using bcrypt
bcrypt.compare(req.body.password, data[0].password, (err, resposne) => {
if (err) {
res.status(500).json(err);
}
//response is either true or false
if (resposne) {
const token = jwt.sign({
email: data[0].email,
userId: data[0]._id
}, "secret",
{
expiresIn: "1h"
})
return res.status(200).json({
message: 'Auth successful',
token: token
})
} else {
return res.status(401).json({ message: 'Auth failed' })
}
})
Increase your expiry limit

How to setup passport-identityserver3

I am new with Node-red and passport-identityserver3.
I am having some difficulties how to setup the passport.
I installed the passport using the C:\Users\xxx>npm install passport-identityserver3 command and try to set the C:\Users\xxx\settings.js file:
adminAuth: {
type:"strategy",
strategy: {
name: "passport-identityserver3",
label: 'Sign in with',
icon:"an icon",
strategy: require('passport-identityserver3').Strategy,
options: {
configuration_endpoint: 'http://localhost:xxxx/.well-known/openid-configuration',
client_id: 'my_client_id',
client_secret: 'my_client_secret',
callback_url: 'http://localhost:1880/auth/strategy/callback',
scopes: ['profile', 'offline_access'],
},
verify: function(token, tokenSecret, profile, done) {
done(null, profile);
}
},
users: [
{ username: "admin",permissions: ["*"]}
]
},
I am getting the following error:
http://127.0.0.1:1880/auth/strategy
Error: Unknown authentication strategy "passport-identityserver3"
at attempt (C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\passport\lib\middleware\authenticate.js:173:37)
at authenticate (C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\passport\lib\middleware\authenticate.js:349:7)
at Layer.handle [as handle_request]
(C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request]
(C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\express\lib\router\index.js:281:22
at Function.process_params
(C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\express\lib\router\index.js:275:10)
at SessionStrategy.strategy.pass
(C:\Users\xxxx\AppData\Roaming\npm\node_modules\node-
red\node_modules\passport\lib\middleware\authenticate.js:325:9)
Thanks you.
You need to run the npm i passport-identityserver3 in the Node-RED User Directory. By default this should be:
C:\Users\xxx\.node-red
not
C:\Users\xxx\
The settings.js file should also be in this directory. When you start Node-RED it will list which User Directory and settings.js it is using

Resources