I am using WL.Client.connect(options) to connect to worklight server from my hybrid app and its returing this error (please refer to the attachment).
I have checked the WL console, my app and adapters are deployed without any issues.
Could not find any error messages in the logs.
function performWlConnect() {
return new Promise(function (resolve, reject) {
// Worklight server connection callback configuration
var wlConnectOptions = {
onSuccess: resolve,
onFailure: reject
};
logger.info('Connecting to the worklight server side...');
// Perform connection to the server side
WL.Client.connect(wlConnectOptions);
});
}
Try with a simple connect and print the error you're getting, it might help you better diagnose your flow.
function wlCommonInit() {
WL.Client.connect({onSuccess:onConnectSuccess, onFailure:onConnectFailure});
}
function onConnectSuccess() {
...
}
function onConnectFailure(response) {
WL.Logger.debug(response);
}
Related
I have a Web app built in Vuejs and has SSO authentification using microsoftTeams.authentication.getAuthToken when running in Teams, or microsoftAuthLib when running in the browser.
Inside the company's network or when connected to the VPN everything works absolutely fine.
We recently opened it outside of the VPN and we created a public certificate for it. So when I disconnect the VPN, it works:
In any browser (outside of Teams).
Teams browser version.
Teams on Android/iPhone.
But it doesn't work on Teams Windows Desktop version, it fails with the following error:
Refused to display
'https://login.microsoftonline.com/.../oauth2/authorize?...' in a
frame because it set 'X-Frame-Options' to 'deny'.
Anybody has an idea what could be the issue? And why would it work on the company's VPN but not outside?And only on specific cases? I am lost, any help would be appreciated.
Thank you
*** EDIT / ADDED SSO REDIRECT CODE ***
import * as microsoftTeams from "#microsoft/teams-js";
import * as microsoftAuthLib from "msal";
import settings from './settings.js';
var msalConfig = {
auth: {
clientId: settings.sso.id,
authority: settings.sso.authority
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
}
};
var requestObj = {
scopes: settings.sso.scopes
};
var myMSALObj = new microsoftAuthLib.UserAgentApplication(msalConfig);
myMSALObj.handleRedirectCallback(authRedirectCallBack);
function authRedirectCallBack(error, response) {
if (error) {
console.log(error);
} else {
console.log("token type is:" + response.tokenType);
}
}
function loginRedirect(requestObj) {
let account = myMSALObj.getAccount();
if (!account) {
myMSALObj.loginRedirect(requestObj);
return false;
} else {
return true;
}
}
function acquireMsalToken() {
return new Promise(function (resolve) {
resolve(myMSALObj.acquireTokenSilent(requestObj).then(token => {
return token.accessToken;
}).catch(error => {
acquireMsalTokenRedirect(error);
}));
})
}
function acquireTeamsToken() {
return new Promise((resolve, reject) => {
microsoftTeams.authentication.getAuthToken({
successCallback: (result) => {
resolve(result);
},
failureCallback: (error) => {
reject(error);
}
});
});
}
function acquireMsalTokenRedirect(error) {
if (error.errorCode === "consent_required" ||
error.errorCode === "interaction_required" ||
error.errorCode === "login_required") {
myMSALObj.acquireTokenRedirect(requestObj);
}
}
var msal = {
autoSignIn: function () {
return loginRedirect(requestObj);
},
acquireToken: async function () {
if (settings.sso.inTeams) {
microsoftTeams.initialize();
microsoftTeams.enterFullscreen();
return acquireTeamsToken();
} else {
let signedIn = msal.autoSignIn();
if (signedIn) {
return acquireMsalToken();
}
}
}
}
export default msal
This error means that you are trying to redirect your tab's iframe to the AAD login flow which in turn is unable to silently generate an auth token for you and is attempting to show an interactive flow (e.g. sign in or consent):
Refused to display
'https://login.microsoftonline.com/.../oauth2/authorize?...' in a
frame because it set 'X-Frame-Options' to 'deny'.
To avoid this issue you need to try and acquire a token silently and if that fails use the microsoftTeams.authentication.authenticate API to open a popup window and conduct the AAD login flow there.
Replacing the acquireTeamsToken() function with the following resolved the issue.
function acquireTeamsToken() {
return new Promise((resolve, reject) => {
microsoftTeams.initialize(() => {
microsoftTeams.authentication.authenticate({
url: window.location.origin + "/ms-teams/auth-start",
width: 600,
height: 535,
successCallback: (result) => {
resolve(result);
},
failureCallback: (error) => {
reject(error);
}
});
});
});
}
I found this documentation very helpful on how to create the Authentication pop up and how to create a Callback window with the Token in it.
You might also want to cache the token and only create a popup when it expires.
This might be because you're using the auth popup option instead of the redirect option in whichever auth library you're using (hopefully MSAL 2.0). Teams is a little different because it's actually launching a popup for you when necessary, so although it sounds a bit strange, you actually want to use the redirect option, inside the popup that is launched. What might help is to look at the new SSO Sample app in the Teams PnP samples.
Go to: %APPDATA%\Microsoft\Teams
Open the file hooks.json (if it's not there, create it)
Add the following to it: {"enableSso": false, "enableSsoMac": false}
That's it, now Teams desktop has the same authentication workflow as the browser version. Have a nice day.
I have created one socket gateway which is working very smoothly with an HTTP request. Now, I am trying to connect socket through https request in NestJs but didn't work for me.
I have also tried to give extra parameters in #WebsocketGateway(5058, { origin : "*:*", secure: true })
I have also checked for NestJs official documentation to work with SSL on the socket but found nothing.
Below is my code which I have created as per documentation.
import { InternalServerErrorException, BadRequestException } from '#nestjs/common';
import { SocketService } from './socket/socket.service';
import { Server, Socket } from 'socket.io';
#WebSocketGateway(5058, { origin : "*:*"} )
export class AppGateway implements OnGatewayConnection, OnGatewayInit {
constructor(private socketService: SocketService) { }
public userIds = [];
afterInit(server: Server) {
console.log("Socket server started");
this.socketService.socket = server;
}
async handleConnection(client) {
try {
console.log(client.id);
this.socketService.socket.to(client.id).emit('status', "connected = " + client.id);
} catch (error) {
throw new InternalServerErrorException(
`Oops.something went wrong, please try again later`,
);
}
}
async handleDisconnect(client) {
this.userIds = this.userIds.filter(user => user.conn_socket_id !== client.id);
}
}
edited:
I can start server and access socket while using an HTTP request, but I am not able to access the socket on HTTPS request.
ex. http://example.com:5058 is working for me,
https://example.com:5058 is not working.
I have fixed it by using a proxy over the socket port so if my socket URL is like https://example.com:5058 then it should be handled from the virtual host and add a proxy to get it working.
The reason for not working is that when you apply HTTPS, it will run on port 443. But now when you are applying an additional port in the URL with HTTPS then it will not run and it will show an error.
Reference for Apache reverse proxy: Link
I have an application flow where:
Clientside Javascript triggers signalR Hub
Asynchronous Call is made
for long running operation
When operation is complete Clientside JavaScript is notified by signalR
I had assumed this would be as simple as:
Server Side:
public async void SendMessage()
{
await Task.Delay(1000);
Clients.All.SendAsync("ReceiveMessage");
}
Client Side:
var hub = new signalR.HubConnectionBuilder().withUrl('/disposeBugHub').build();
this.hub.on("ReceiveMessage", function () {
alert('Message Received');
});
this.hub.start()
.then(function () {
hub.invoke("SendMessage");
})
.catch(function (err) {
return console.error(err.toString());
});
However the Clients.All.SendAsync("ReceiveMessage"); call always throws a System.ObjectDisposedException: 'Cannot access a disposed object.' Exception.
This appears to be expected behavoir and not a bug, so my question is how do i programmatically acheive the desired workflow? I assume there must be a well known pattern to acheive this but I cant find it online.
First of all , remove void method for long running process. use Task return type method .
Try this.
public async Task SendMessage()
{
await Task.Delay(10000);
Clients.All.SendAsync("ReceiveMessage");
}
I am getting WL.JSONStore is undefined error in mobile browser simulator while I am trying to use JSONStore in my mobile application.I am using IBM mobilefirst (version 8.0.0-2017091111).
function wlCommonInit(){
WL.JSONStore.init(collections, options).then(function () {
alert("intialized successfully");
}).fail(function (errorObject) {
alert("failed to initialize collection\n"+ JSON.stringify(errorObject));
});
document.getElementById("btn_submit").addEventListener("click", onSubmit, false);
}
function onSubmit(){
var collectionName="people";
var data={firstName:$('#first').val(),middleName:$('#middle').val(),lastName:$('#last').val()};
WL.JSONStore.get(collectionName).add(data, options).then(function () {
alert("added data successfully");
}).fail(function (error) {
});
}
Could you specify which version of 'cordova-plugin-mfp-jsonstore' your app is using (run command 'cordova plugin ls').
Did you follow this tutorial
Link
Add cordova jsonstore plugin
cordova plugin add cordova-plugin-mfp-jsonstore
See more: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/jsonstore/cordova/#adding-jsonstore
https://www.npmjs.com/package/cordova-plugin-mfp-jsonstore
I have a React-native app that I need to connect with IoT (AWS), with websockets. I currently use the package react-native-paho-mqtt to connect my app. Here is my code :
function getClient(onConnect, onConnectionFailed, onConnectionLost,
onMessageArrived) {
logger.trace('getClient()');
const clientID = uuidV4();
// Create a client instance
const client = new Paho.MQTT.Client(signedUrl, clientID); // eslint-disable-line no-undef
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({
keepAliveInterval: 15,
onSuccess: onConnect,
onFailure: onConnectionFailed,
});
return client;
}
5 minute after my main connection, I get an error when I try to connect an other client. I get this error: AMQJS0007E Socket error:{0}.. I do not have any more information about the error.
Does anyone know what is happening or how to solve this problem ?