Oauth + Laravel + Vuejs + MongoDB 500 Internal Server Error - mongodb

everyone. I am currently developing a web app. I started to develop on a laptop. Then I mapped the code folder on the laptop to my pc. On my laptop, everything works correctly. But on the PC i cant get authenticated. I get 500 Internal server error. I am using Oauth, Laravel, laravel passport, vuejs and mongodb. i am currently accessing the mongodb server remotely if it matters.
Here is the login method
methods: {
login(){
var data = {
client_id:'58a08f3588053a6d947dc902',
client_secret:'E1STUJipgmCO2h9gtkN2Vl1fTpgJCuiW2SrktshM',
grant_type:'password',
username:this.userid,
password:this.password
}
this.$http.post("http://localhost:8000/oauth/token", data)
.then(response => {
console.log(response)
})
/*
.then(function(response){
console.log(response)
})*/
}
}
Thank you

Related

Keycloak.js can not get access token when login with Google and Facebook

I'm build a system for our company using Keycloak. I use keycloak.js for by-pass default login page of Keycloak.
function myFunction() {
let kcLogin = keycloak.login;
keycloak.login = (options) => {
options.idpHint = 'facebook';
kcLogin(options).then(auth => {
alert("keycloak Login");
if(auth) {
alert("token" + kc.token);
} else {
alert("auth is null");
}
});
};
keycloak.init({ onLoad: 'login-required' }).then(function(authenticated) {
alert(authenticated ? 'authenticated' : 'not authenticated');
}).catch(function() {
alert('failed to initialize');
});
}
But I can NOT get access token / refresh token after login.
I check: keycloak.token = undefined.
Please help me!
PS: I always get exception of keycloak.init then redirect to facebook login ( or google login )
alert('failed to initialize');
Thank you so much.
Code here: https://github.com/loizenai/SpringBoot-Keycloak-Social-Authentication-Py-Pass-Default-Login/tree/main/SpringBootKeyCloakSocialSignIn
You are trying to configure your backend and frontend with Keycloak.
Either you just have to configure your backend to integrate with your keycloak or Integration your frontend application and your backend will only verify the token.
The current application architecture you are following is an MVC pattern.
Where your spring boot(backend) application controls the integration with Keycloak.
Please refer to this article: Secure spring boot 2 using Keycloak
What you are trying to target follows this kind of architecture pattern:
Secure Vue.js apps with Keycloak | DevNation Tech Talk
In the above reference, I have used the Vue application but you can use your vanilla html/js application as well to integrate with keycloak.
First, try keycloak login flow in your application and then you can enable social login.

Connecting Aurelia with backend API

Context: I'm starting a new project for my company. It's been many years since I've done some web development and decided to build it using the latest platforms (so I'm a still new to all of this).
Current stack:
Aurelia frontend (running on localhost:9000)
Backend REST API using ExpressJS (running on localhost:8000)
PostGreSQL database running on AWS, providing data for the backend
Question: I can't seem to connect my frontend with my backend properly.
Here is my code:
import {inject} from "aurelia-framework";
import {HttpClient} from "aurelia-http-client";
#inject(HttpClient)
export class Login {
constructor(httpClient){
this.http = httpClient;
}
signIn() {
const url = 'http://localhost:8000/api/user/demo/test';
this.http
.get(url)
.then(data => {
console.log("data");
console.log(data);
})
.catch(error => {
console.log('Error getting ' + url);
console.log(error);
});
};
}
This always end up in the catch block, with a "response: ProgressEvent"
If I put the url in the browser I get a proper JSON:
{"status":"success","data":[],"message":"Retrieved ALL users"}
The code above only works for 'local' content, i.e. localhost:9000. As soon as I need content from somewhere else I get this error. What am I missing?
I think that CORS is not allowing you to access localhost:8000 from localhost:9000. To solve this, you should enable your ExpressJS server to accept CORS requests from localhost:9000 (or all hosts using a wildcard "*").
Look into these resources:
https://enable-cors.org/server_expressjs.html
https://github.com/expressjs/cors
Or search Google for 'expressJS cors'.

LDAP authentication fails on ripple and actual device but not on browser

I'm trying to get an authorization token for an Ionic App from a LDAP service in a remote server.
I can get the auth token when I run the Ionic App in the browser with the command ionic serve and when I use Postman,
BUT it takes lot of time and eventually fails when I debug using ripple for the App or when I test on the phone or tablet.
The error says:
status: 503
statusText: Service Unavailable
data: html code from http://s3.amazonaws.com/heroku_pages/error.html
var deferred = $q.defer();
var req = {
method: 'GET',
url: 'http://host:port/adap?bind=token',
headers: {
Authorization: 'Basic <username>:<password>'
}
};
$http( req )
.then(function(data, status, headers, config) {
console.log(data);
deferred.resolve(data.data);
})
.catch(function(data) {
console.error(data.data);
deferred.reject(err);
});
return deferred.promise;
Does anybody have some hint about this issue?
Thanks in advance
For what you say the service is available, so the problem must be in the app side.
Check IP tables, and check ripple's proxy and set it to none.

Socket.io, Passport, MongoDB & passport.socketio broken in production

I built a nodejs application relaying on socket.io, using Passport & passport.socketio for authentication and authorization, and mongodb with connect-mongo for session store.
It works well on my laptop, but when I moved to the Cloud (Azure-VM) I started getting strange errors.
05-02-2014, 11:47:06.500 Listening on port 8081 (https)
/home/azureuser/myapp/node_modules/mongodb/lib/mongodb/connection/base.js:242
throw message;
^
Error: Error in session store:
Error: failed to deserialize user out of session
at Object.io.set.passportSocketIo.authorize.fail (/home/azureuser/myapp/lib/express/socketio.js:25:23)
at /home/azureuser/myapp/node_modules/passport.socketio/lib/index.js:48:21
at /home/azureuser/myapp/node_modules/connect-mongo/lib/connect-mongo.js:229:23
at /home/azureuser/myapp/node_modules/mongodb/lib/mongodb/collection/query.js:147:5
at Cursor.nextObject (/home/azureuser/myapp/node_modules/mongodb/lib/mongodb/cursor.js:733:5)
at commandHandler (/home/azureuser/myapp/node_modules/mongodb/lib/mongodb/cursor.js:713:14)
at /home/azureuser/myapp/node_modules/mongodb/lib/mongodb/db.js:1806:9
at Server.Base._callHandler (/home/azureuser/myapp/node_modules/mongodb/lib/mongodb/connection/base.js:442:41)
at /home/azureuser/myapp/node_modules/mongodb/lib/mongodb/connection/server.js:485:18
at MongoReply.parseBody (/home/azureuser/myapp/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
Any ideas where to start?
ok I found it, passport.socketio has its depends on Passport and has it's own "version" of passport.
Which means that in my code when I set serializeUser/deserializeUser it only affects the passport I use for the REST:
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(id, done) {
done(null, id);
});
While passport.socketio by default does:
var defaults = {
passport: require('passport'),
key: 'connect.sid',
secret: null,
...
};
Meaning the serializeUser/deserializeUser are not used, which in turn causes this:
Error: failed to deserialize user out of session
The solution is pretty simple just to pass the passport used for the REST to the passport.socketio
io.set('authorization', passportSocketIo.authorize({
passport : passport,
cookieParser: express.cookieParser,
...
}));

How to use node.js Context.IO behind a department proxy?

Here is my node.js code to use Context.IO in a RESTful way rather than IMAP.
var ContextIO = require('contextio');
var ctxioClient = new ContextIO.Client({
key: 'MY_KEY',
secret: 'MY SECRET'
});
ctxioClient.accounts().get(function(err, res) {
if (err) throw err;
console.log(res);
});
When I executed the above code on my dormitory computer, everything worked fine. However, when I executed the code on my office computer, which is behind a departmental proxy, the code simply timed out. My department provides both http and socks proxies for internet access. The question is how to set it up in node.js?
By the way, I also tried
socksify node code.js
It did not time out. Instead, it just did not response.