Synology SSO Server - javascript

I have a Synology DS212j and already set up the apache and now also SSO Server. In the SSO Server Settings I added a new Application (Name, REdirect URI). My Code now is:
<html>
<head>
<!-- include Synology SSO js -->
<script src="http://NASADRESSE:5555/webman/sso/synoSSO-1.0.0.js"></script>
</head>
<body>
<script>
function setButton (logged) {
if (logged) {
document.getElementById('button').innerHTML = '<button onclick="SYNOSSO.logout()">Logout</button>';
} else {
document.getElementById('button').innerHTML = '<button onclick="SYNOSSO.login()">Login</button>';
}
}
function authCallback(reponse) {
console.log(JSON.stringify(reponse));
if (reponse.status == 'login') {
console.log('logged');
setButton(true);
}
else {
console.log('not logged ' + reponse.status);
setButton(false);
}
}
SYNOSSO.init({
oauthserver_url: 'NASADRESSE:5555',
app_id: '9a23da153795803e0334d9873b0013dd',
redirect_uri: 'NASADDRESSE/?redirect',
callback: authCallback
});
</script>
<h1> Syno SSO test</h1>
<p id='button'></p>
</body>
</html>
NASADRESSE is correct and my Rooter redirect port 5555 to 5000. Wenn I click login, a popup window opens where I can loggin with my NAS user. But it always says its a wrong password. But I entered the right one.

Why in your script link included .ch but in your config the domain have no .ch
http://NASADRESSE.ch:5555/webman/sso/synoSSO-1.0.0.js
SYNOSSO.init({
oauthserver_url: 'NASADRESSE:5555',
app_id: '9a23da153795803e0334d9873b0013dd',
redirect_uri: 'NASADDRESSE/?redirect',
callback: authCallback
});
May it go with wrong config?

1 - install the Directory Server package, enable LDAP server
2 - configure your DSM to connect to it (Control Panel-> Domain/LDAP)
3 - connect using the LDAP users

Related

Why does my Webapp not work with Google's OAuth login system?

I am attempting to build a basic Webapp which has a login with Google button. When the user logs in, I want the web app to change the 'login' button to change to a 'logout' button and also display the user's basic information such as their name which it obtains from their Google profile.
My site successfully opens the Google login page. I am able to click on my Google profile to login and am successfully redirected back to my site. However, nothing changes on my website. The login button still remains a login button and no information is displayed.
I want my site to display the user's information and also change the "login" button to a "logout" button.
I have ensured that my Authorised JavaScript origin (http://localhost:8000) and my Authorised redirect URL (http://localhost:8000/callback) is set correctly. I have also added my CLIENT_ID to my index file. I have also ensured that my client ID is correct.
<html>
<head>
<script src="https://apis.google.com/js/platform.js"></script>
<script>
var googleUser;
var profile;
var auth2;
function onSignIn(googleUser) {
profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
// Change the sign-in button to display the user's details
document.getElementById("g-signin2").style.display = "none";
document.getElementById("user-details").style.display = "block";
document.getElementById("user-name").innerHTML = profile.getName();
document.getElementById("user-email").innerHTML = profile.getEmail();
document.getElementById("user-image").src = profile.getImageUrl();
}
function signOut() {
auth2.signOut().then(function () {
console.log('User signed out.');
// Change the sign-in button back to the original state
document.getElementById("g-signin2").style.display = "block";
document.getElementById("user-details").style.display = "none";
});
}
gapi.load('auth2', function() {
gapi.auth2.init({
client_id: 'my-client-id is in here',
redirect_url: 'http://localhost:8000/callback',
scope: 'profile email'
}).then(function(auth) {
auth2 = auth;
// Check if user is already signed in
if (auth2.isSignedIn.get()) {
onSignIn(auth2.currentUser.get());
}
});
});
</script>
<style>
.g-signin2 {
width: auto;
margin: 0;
}
#user-details {
display: none;
}
</style>
</head>
<body>
</style>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" id="g-signin2"></div>
<div id="user-details">
<p id="user-name"></p>
<button onclick="signOut()">Sign Out</button>
</div>
</body>
</html>
If you check the debugger F12 most browsers you will find your code is throwing an error and a warning
"You have created a new client application that uses libraries for user authentication or authorization that will soon be deprecated. New clients must use the new libraries instead; existing clients must also migrate before these libraries are deprecated. See the Migration Guide for more information."
There is really no reason for you to bother fixing this code it will stop working very soon. You should use the new Web identity
code
<html>
<body>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<script>
function handleCredentialResponse(response) {
console.log("Encoded JWT ID token: " + response.credential);
}
window.onload = function () {
google.accounts.id.initialize({
client_id: "[REDACTED]",
callback: handleCredentialResponse
});
google.accounts.id.renderButton(
document.getElementById("buttonDiv"),
{ theme: "outline", size: "large" } // customization attributes
);
google.accounts.id.prompt(); // also display the One Tap dialog
}
</script>
<div id="buttonDiv"></div>
</body>
</html>

Why cannot I connect to hivemq broker the socket keep on getting closed when I try to reconnect?

I have wriiten to publish a rfid value and while subscribing inside javascript, the socket connection is lost and I have attached the screenshot of my console.
value.php
<body>
<div id="print"></div>
<!-- jquery library -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<!-- paho MQTT library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.min.js" type="text/javascript"></script>
<script src="app.js"></script>
</body>
I am trying to connect using hivemq broker and using port number of 8000 but it's not connecting.
app.js
var hostname = "broker.hivemq.com";
var clientId = "someid";
var username = "username";
var password = "password";
var subscription = "sometopicname";
mqttClient = new Paho.MQTT.Client(hostname, 8000, clientId);
mqttClient.onMessageArrived = MessageArrived;
mqttClient.onConnectionLost = ConnectionLost;
Connect();
function Connect() {
mqttClient.connect({
onSuccess: Connected,
onFailure: ConnectionFailed,
userName: username,
password: password,
useSSL: false
});
}
function Connected() {
console.log("Connected");
mqttClient.subscribe(subscription);
}
function ConnectionFailed(res) {
console.log("Connection failed: " + res.errorMessage);
}
function ConnectionLost(res) {
if (res.errorCode !== 0) {
console.log("Connection lost:" + res.errorMessage);
Connect();
}
}
function MessageArrived(message) {
console.log(message.payloadString);
}
First, are you 100% sure that port 8000 is configured to support MQTT over Websockets.
Second, you appear to have a hard coded clientId value, with this you will only be able to have 1 client connected at a time. EVERY Page needs to have a unique clientId, if you try and connect 2 clients with the same clientId (2 or more instances of the page in any browser) will kick the other one off the broker. ClientIds MUST be globally unique.
If after you have checked the first and fixed the second you should check the broker logs to see why it may be closing the connection.

How to add functionality of Google SIgn-In in Phonegap Hybrid HTML app

How to implement Google Login in Phonegap App & also how to check whether the user is logged in or not as soon as the user opens up the app ? I am already aware of the EddyVerbruggen Plugin but it doesn't tells the status of login, it just logs in the user and also its trysilentLogin method doesn't works (yields error : 4) . Without knowing the login status how can I direct my users to the welcome page of my app.
HTML :
<body onload="init()">
</body>
config.xml :
<plugin name="cordova-plugin-googleplus" source="npm" spec="5.2.1">
</plugin>
login.js :
function init()
{
document.addEventListener("deviceready", onDeviceReady, false);
}
var onDeviceReady = function()
{
window.plugins.googleplus.trySilentLogin(
{
'scopes': '',
'offline': false
},
function (obj) {
alert(JSON.stringify(obj)); // do something useful instead of alerting
alert(' YES LOGGED IN ::: GOOGLE ');
},
function (msg) {
alert(' GOOGLE LOGIN error: ' + msg); //here comes the error : 4
}
);

Need help for routing in node js application

I have a nodejs application,where I want user to go to login page by default if he tries to access any route or any file(html/js).If the credentials are correct he should go to /index page. I've added post call in my main app.js file and it is working from postman,but unaware of how to use in my node app itself.
app.js
app.get('*',function (req, res) {
res.redirect('/login');
res.sendFile(path.join(__dirname+'/login/login.html'));
});
app.get('/index',function(req,res){
res.sendFile(path.join(__dirname+'/index/index.html'));//on success of login it should be here
});
app.post('/login',function(req,res){
var username = req.headers.uname;
var password = req.headers.pwd;
var uname = "*****";
var pwd = "*******";
var login = false;
if(uname == username && pwd == password){
console.log("success");
login = true;
}
else{
console.log("fail");
login = false;
}
if(login == true){
res.send("Hello");//It should route to my /index page
}else{
res.send("Bad luck"); //Invalid credentials
}
});
In login folder I have my login.html and my login .js
login.html
<html>
<head>
<script src="/login.js"></script>
</head>
<body>
<div>
Username:<input type="text" id="uname">
</div>
<div>
Password:<input type="text" id="pwd">
</div>
<div>
<button type="submit" onclick="login();">Login</button>
</div>
</body>
</html>
How can I call login function so that it uses the above post call from my app.js and on success it goes to index page and also by default it should go to login page..Can some one help here
You need to use a middleware in node. In your case, let's call it auth, it will check the credentials, if they are correct it will call the next handler in the chain, if not, it will issue a response with 401 (or 403 if forbidden) status code to the client.

Google Calendar API javascript Error:Origin Mismatch

I'm working on a simple javascript code I found here: http://googleappsdeveloper.blogspot.com/2011/12/using-new-js-library-to-unlock-power-of.html
It basically acquires authentication to a google Calendar and retrieves the list of events contained in it. I have registered my web application and obtained a client ID and API Key.
I'm facing this error: "Error: Origin mismatch", I'm running the javascript locally using localhost and I set my homepage in the google application registration to localhost as well.
any help would be immensely appreciated.
the code:
<html>
<body>
<div id='content'>
<h1>Events</h1>
<ul id='events'></ul>
</div>
<a href='#' id='authorize-button' onclick='handleAuthClick();'>Login</a>
<script>
var clientId = '506979856128.apps.googleusercontent.com';
var apiKey = 'AIzaSyAGbQAZQU0YNL8hK5EU69exIg7_sOg3JoA';
var scopes = 'https://www.googleapis.com/auth/calendar';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
checkAuth();
}
function checkAuth() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},
handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
if (authResult) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: clientId, scope: scopes, immediate: false},
handleAuthResult);
return false;
}
function makeApiCall() {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list({
'calendarId': 'primary'
});
request.execute(function(resp) {
for (var i = 0; i < resp.items.length; i++) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(resp.items[i].summary));
document.getElementById('events').appendChild(li);
}
});
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"> </script>
</body>
</html>
I got the same error origin mismatch today.after bit of search i got the reason.
While creating the Google Api Access,we have to specify Authorized Redirect URIs and Authorized Redirect URIs.
Now if you call the Login from URIs other than specified in Authorized Redirect URIs, error:Unknown Origin is thrown
FYI:I have seen that you are running the javascript locally using localhost.
It means that You have not added localhost uri to Authorized Redirect URIs.
But Don't waste your time doing that.Authorized Redirect URIs will not accept localhost uri.It's due to Chrome's same origin policy.and If you run chrome with the disable-web-security flag, it'll work locally too.
The problem of origin mismatch can be solved by taking care for Redirect URIs and Javascript Origins when creating Client ID in Google Developers Console.
The Javascript Origins should not end with /.
Example: http://example.com/ --> The correct format will be http://example.com.

Categories

Resources