Iot Core API /api/wifi/network - Bug? - raspberry-pi

The Device Portal Core API contains a Post method for connecting/disconnecting Wifi. This project by Falafel is a demonstration of that.
All other methods in that project work fine but when trying to connect, the response returned is StatusCode 500 "Internal server error". I'm running Windows Iot Core v.10.0.16299.309 on a Raspberry Pi3.
The portals authentication is built and passed in the request and the wifi Key is encoded in base 64. The request uri will look something like the following.
http://192.168.137.1:8080/api/wifi/network?interface=1A6E4125-B554-40CB-916E-EE55CEBAD6C8&op=connect&ssid=MyWifiSSID&key=42dhi2nuk%182v&createprofile=yes
Does anyone see something wrong with this approach or can the error be duplicated? Thanks for your help.

You also need encode WiFi SSID to base64 format. In C# you can do it like this:
byte[] stringToBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(wifiSsid);
string encodedValue = System.Convert.ToBase64String(stringToBytes);
For your referenced project, you need use EncodeTo64(this.SelectedWifi.SSID) instead of this.SelectedWifi.SSID in the Post method for connecting Wifi like this:
using (HttpResponseMessage response = await client.PostAsync(string.Format("http://[IP ADDRESS]:8080/api/wifi/network?interface={1}&ssid={2}&op=connect&createprofile=yes&key={3}", this.DeviceName, this.InterfaceGUID, EncodeTo64(this.SelectedWifi.SSID), EncodeTo64(this.WifiKey)), null))

Related

REST Client extension - API response as HTML

I wanted to use vs code's extension REST client for testing purposes. So I used a curl of an existing API running on my local machine. But instead of JSON, I got HTML as a response. The curl works as expected in the terminal but not with the extension.
The same Behaviour is with another extension named Thunder Client.
Postman is getting JSON responses for the same API I believe that issue lies within vs code itself, I just don't know how to resolve it.
According to this article:
https://softwareengineering.stackexchange.com/questions/207835/is-it-ok-to-return-html-from-a-json-api
If you have declared you only accept one format in the header then the service should only send back that format or throw an error. If you have not put an ACCEPT in the header, the the service may send back whatever.
Check what is in the ACCEPT header:
But also check how Thunder Client translates the call in powershell:
I see that in my call the response is translated to JSON. I would guess that most REST clients are assuming that users want to work in JSON. Maybe that's what your two REST clients are doing?

Audio source with axios stream?

I have an HTML5 audio control and would his src property is pointing to my middleware, an express / node server that delivers a streaming mp3 file.
On the middleware I'm using res.pipe() to output the mp3 file.
It's working great with one caveat: I can't send my authorization header.
So I want to use axios to access my middleware which works fine but I can't figure out how to "feed" the audio element.
If I do:
const response = axios.get('/api/stream',{requestHeaders:'stream'});\
myAudio.src = response;
It throws an error and I'm block from there...
Thanks for any help :)
Finally managed to pass a token as a get parameters instead of trying to use axios.

How to use postman API client with openchain API server

I have just installed openchain (http://openchain.org)
I can check it on http://nossl.wallet.openchain.org/ but I would like to check API using Postman Rest client tool on my PC.
I'm using postman rest client and I have tried URI many times but response is empty : https://docs.openchain.org/en/latest/api/method-calls.html
Please give some advises, thanks in advance !
You should want it to look like something like this picture. Check your headers also, when I use the URL https://www.openchain.org/endpoint/query/recordversion?key=FFFF I get nothing and then when I check the headers I see there is a 404 status which means I was able to communicate with the server but it couldn't find my key. Which makes sense since I am just passing a random key. So see if you are getting a 404 error in your headers and if so then make sure your key is correct.

Retrieve Pyramid's auth_tkt via HTTP response headers on mobile client

I am writing a mobile iOS application, which communicates with a Pyramid app on the backend. I am currently using Pyramid's built-in AuthTktAuthenticationPolicy.
I've met some speed bumps while attempting to authenticate via a mobile client (iPhone). For starters, how would I send and retrieve the auth_tkt cookie that is set by Pyramid.
I understand how this works with a web browser, but, if I want to send this "auth_tkt cookie" in the HTTP response, how can I accomplish this? How do I actually get the auth_tkt secret string. For example, what if I'd like to return it in the JSON body or a custom header of my choosing rather than as the cookie set by Pyramid's remember function?
Secondly, in future requests sent by the client what header do I set with the auth_tkt secret string so that Pyramid recognizes it and appropriately authenticates the client?
Using the Pyramid Helper Classes here, it looks like you can create your own auth_tkt and access it as well. Example from docs:
token = AuthTicket('sharedsecret', 'username',
os.environ['REMOTE_ADDR'], tokens=['admin'])
val = token.cookie_value()
The headers is a webob ResponseHeaders object, it derives from webob multidict. You can get it value by using this:
set_cookie = request.response.headers['set-cookie']
You can refer this link: webob multidict

how to see httpS request & headers on win?

I'm working on developing some tests that will work with rest api.
I have restClient in Firefox and my eclipse where I run requests through HttpsURLConnection.
My problem is that sometimes when i send Exactly Same requests through restClient and java - i get different responses. I’ve been having that problem forever..
Usually I’d find the way around after sometime. It would be super helpful If I could see requests that were sent and compare it...
I don't have adminRights on my Pc, so i was looking into some portable apps. I also have wireShark but it wouldn't help.
try that tool, it is called burpsuite. You can install cert to your burpsuite and then once it is all set you will be able to read all requests.
http://portswigger.net/burp/
Hope that helps.
If you have the SSL private key, then you can decrypt the HTTPS packet using the Wireshark.
http://wiki.wireshark.org/SSL
If not, it is difficult.
You can see http headers of any website on any browser like this:
javascript:var req = new XMLHttpRequest();req.open('GET', document.location, false);req.send(null);var headers = req.getAllResponseHeaders().toLowerCase();alert(headers);
Paste above code to address bar of browser and hit enter.