Openfire in-band-registration via Bosh not working with Strophe/Strophe.register.js - xmpp

I previously asked a similar question about ejabberd, however ejabberd was giving other problems, so I switched to openfire. For the sake of not making the original qestion to cluttered, I decided to create a new question, since this question pertains to openfire and is a different issue than the one I was having with ejabberd.
So, here goes the question:
I have a strophe.js xmpp client, which connects to an openfire 3.10.0 alpha server running on the Amazon cloud. I need 3.10.0 alpha over 3.9.3 because of a bfix which is included in the former, but not the latter.Anyway, since this is a strophe client, I have enabled bosh, and I can see it running at myAWSDNS.com:7070. I am able to connect to the server via my client using this bosh service and existing accounts, and send messages back and forth so it seems to be functioning ok.
I would also like to add in-band registration, for which I use strophe.register.js
This is the code I use for this:
var tempConn = new Strophe.Connection("http//myAWSDNS.com:7070/http-bind/");
tempConn.register.connect("myAWSDNS.com", function (status) {
if (status === Strophe.Status.REGISTER) {
// fill out the fields
connection.register.fields.username = "juliet";
connection.register.fields.password = "R0m30";
// calling submit will continue the registration process
connection.register.submit();
} else if (status === Strophe.Status.REGISTERED) {
console.log("registered!");
// calling login will authenticate the registered JID.
connection.authenticate();
} else if (status === Strophe.Status.CONFLICT) {
console.log("Contact already existed!");
} else if (status === Strophe.Status.NOTACCEPTABLE) {
console.log("Registration form not properly filled out.")
} else if (status === Strophe.Status.REGIFAIL) {
console.log("The Server does not support In-Band Registration")
} else if (status === Strophe.Status.CONNECTED) {
// do something after successful authentication
} else {
// Do other stuff
}
});
This seems to work fine, as it enters the first if-bracket (status === Strophe.Status.REGISTER), and tries to set connection.register.fields.username = "juliet";
However, here, when executing that line, it jumps into strophe.js line 2476:
if (this.connect_callback) {
try {
this.connect_callback(status, condition);
} catch (err) {
Strophe.error("User connection callback caused an " +
"exception: " + err);
}
}
where 2476 is the code in the catch(err) { ...... } bracket.
If I inspect err, this is what I get:
So message: connection is not defined and, obviously, the regstration doesnt work, and I am not sure why. Does anyone have any input on this?
Thanks, and best regards,
Chris

You might not like this answer... The reason for connection == undefined is because you named it tempConn.

Related

Is it possible to know that the error is CORS in Axios?

Axios gives us the interception ability. I have created a response interceptor to get errors.
This is my code:
const errorInterceptor = error => {
if (error.code === 'ERR_NETWORK') {
throw new Error('Network is not connected')
}
// The rest of the code
}
However, if I get the CORS error, I can't find any information to know that it was a CORS error.
Why do I need this?
I want to provide meaningful messages to my users.
If network is disconnected, I want to show You are not connected to the internet. If it's CORS, I want to show API is not configured properly for CORS, please inform the administrator.
How can I know whether the error is CORS or not?
I have created an interceptor and I have tried to extract data from it.
axios.interceptors.response.use((response) => response, (error) => {
if (typeof error.response === 'undefined') {
alert('A network error occurred. '
+ 'This could be a CORS issue or a dropped internet connection. '
+ 'It is not possible for us to know.')
}
return Promise.reject(error)
})

Flutter Plugin for automatic wifi connection without prompting something from the user

The specific use case is for a wearable application (Wear OS) that I want to automatically connect to a wifi network that is specified in a config file for easy cross-site deployments without even telling that it is being done. I have tried wifi_iot and plugin_wifi_connect with some odd results. Both seemed to connect to the correct ssid, but they gave some sort of weird prompt that said something about connecting to the device and seemed to actually mess up the connection afterward.
wifi_iot implementation:
check for wifi setting
WiFiForIoTPlugin.isEnabled().then((val) {
_isEnabled = val;
});
print('isEnabled: $_isEnabled');
//check if connected to wifi
WiFiForIoTPlugin.isConnected().then((val) {
_isConnected = val;
});
print('isConnected: $_isConnected');
//enable and connect if not
if (!_isEnabled) {
//enable wifi
WiFiForIoTPlugin.setWiFiAPEnabled(true);
WiFiForIoTPlugin.setEnabled(true);
}
if (!_isConnected) {
//connect to wifi
WiFiForIoTPlugin.connect(_ssid,
password: _psk, security: NetworkSecurity.WPA);
}
plugin_wifi_connect implementation:
var _connectedTo = await PluginWifiConnect.ssid;
print("Comparing $_connectedTo to $_ssid"); //#_connectedTo returns <unidentified_ssid>#
if (_connectedTo.toString() != _ssid) { //#this always fails
try {
await PluginWifiConnect.connectToSecureNetwork(_ssid, _psk,
saveNetwork: true);
print("Connected to $_ssid");
} catch (e) {
print("Couldn't connect to $_ssid");
}
} else {
print("Already connected to $_ssid");
}
Does anyone have any experience with this? Possibly that I am not using the correct permissions for this or if I need to make something if this is even possible anymore. There seemed to be some changes for API above 29 that changed certain things about it. The plugin_wifi_connect did not have much documentation and seems like it might be based on an older package that wasn't null safe that was not really up to date with the same documentation.

Handling JWT token expiration in a React based application?

We are in the process of building a web based application, using React and making use of a REST based server. The question that came up is how to best manage a previously authenticated connection becoming unauthenticated and whether there are any React or React/Redux design patterns for this?
Previous designs had used sessions, but since the REST server is meant to be stateless, the current REST server design will probably look at follows:
POST /auth/authenticate --> Authenticate and provides a token
DELETE /auth/token --> Invalidates the token, black-list token
PUT /auth/token --> Renews token, if still valid
GET /auth/token --> Indicates if token is still valid
On the client side the current draft design is to wrap the fetch function with our own function for dealing with checking the response state and then either calling a client side service for invalidating state and redirecting to login page or doing the same thing with Redux. We are also looking to add an interval timer to check the token we have and then automatically do the same thing if the 'exp' field is present and past.
The function we have at this point is (it does not take care of revalidation of token, at this point, to prevent an activate 'session' expiring):
function handleFetchResponse(fetchResponse) {
let newResponse;
try {
return fetchResponse.then((response) => {
newResponse = response;
const contentType = response.headers.get('content-type');
if (contentType && contentType.indexOf("application/json") !== -1) {
return response.json();
} else if (response.status === 200) {
return response.blob();
} else {
if (response.status === 401) {
forceLogout();
}
throw new RequestError(response.statusText, response.status);
}
}).then((responseBody) => {
if (newResponse.status === 401) {
forceLogout();
return;
} else if (newResponse.status !== 200) {
if (responseBody) {
throw new RequestError(
responseBody.details ||
newResponse.statusText,
newResponse.status
);
}
throw new RequestError(newResponse.statusText, newResponse.status);
}
return responseBody;
});
} catch (error) {
console.error('handleFetchResponse:error', error);
return Promise.resolve(err)
.then((err) => {
throw err;
})
}
}
It would be called via:
return handleFetchResponse( fetch(...) );
Is this an acceptable design or are they ways to improve on this?

Magento 2.0.7: Something went wrong with the subscription.

get error whe subscription Newsletter. How can fix?
Here is the problem and the solution to this bug:
When we enter an new email address (one that is not connected to an extisting subscriber), the subscriber object ($this) has no id ($this->getId(); // null) yet in Magento\Newsletter\Model\Subscriber::subscribe.
The verification email is sent out before the subscriber is saved, thus the subscriber id is missing from the verification link. The link does not do anything when you click on it because the verification method in Magento\Newsletter\Controller\Subscriber\Confirm::execute rejects the link because of the missing id.
You can easily mend the problem by calling $this->save() before calling $this->sendConfirmationRequestEmail();
try {
$this->save();
if($isConfirmNeed === true && $isOwnSubscribes === false)
{
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
return $this->getStatus();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
I simply moved the ''save'''- call a few lines up. sendConfirmationRequestEmail and sendConfirmationSuccessEmail do not seem to alter the $thisobject, so this is a valid change that does not break anything else.
I just changed the "Disable Email Communications" to yes in Magento 2 ( Stores > Configuration > Advanced > System > Mail Sending Settings > Disable Email Communications).

Can't connect to XMPP server (openfire) with HTTP binding

I'm trying to learn XMPP protocol to make web applications using it.
So, I've installed a XMPP daemon called openfire, I configured it to support HTTP-Bind, I can connect to it using Pidgin and the default XMPP protocol.
The problem is that I can't connect to it using HTTP-Binding. In pidgin I have some options when I'm connecting to specify method whici I want to use to connect to server. If I set it to connect using HTTP-Bind it fails with this message: No session id given.
At the client side, I'd use Strophejs try to make this connection, but it doesn't work too. I have something like this:
var conn = new Strophe.Connection("http://chat.dev/http-bind");
Where http://chat.dev/http-bind is the location to the XMPP daemon. I've been forwarded this location to be set on the properly port in apache virtualhost, so the http://chat.dev/http-bind will point to the same thing as http: / / 127.0.0.1:7070.
conn.connect("test5", "test5", some_callback);
function some_callback(status)
{
if (status == Strophe.Status.CONNECTING) {
console.log('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
console.log('Strophe failed to connect.');
} else if (status == Strophe.Status.DISCONNECTING) {
console.log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
console.log('Strophe is disconnected.');
} else if (status == Strophe.Status.CONNECTED) {
console.log('Strophe is connected.');
// connection.disconnect();
}
}
This will return: "Strophe is connecting."
Well, I don't know the answer, I've been reading a book about XMPP and Strophe, but this book doesn't cover this aspect and the documentation which I've found also doesn't help me.
Thanks.
Try this-
var conn = new Strophe.Connection("http://chat.dev/http-bind/");
Need to put '/' in the end. Worked for me.