Audio source with axios stream? - axios

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.

Related

How to fetch audio from my api with protected urls using audioplayers (flutter)

I'm trying to play audios using audioplayers on my flutter app. My audio url are coming from an API that i've build using Java spring security and the urls to those audios are protected (I'm using token authorization (bearer token))
Fetching data from the internet From Flutter's documentation.
And other Networking tutorials.
According to AudioPlayer's documentation:
The remote URL must be accessible and not be a redirect. If it's not an audio file, it does a redirect, it requires some headers, cookies or authentication, it will not work.
Then, AudioPlayer is not an option to use. On the other hand, just_audio could support headers parameter, then you may set the authorization header:
await player.setUrl(url,headers: {'Authorization': tokenValue});

Data Factory can't download CSV file from web API with Basic Auth

I'm trying to download a CSV file from a website in Data Factory using the HTTP connector as my source linked service in a copy activity. It's basically a web call to a url that looks like https://www.mywebsite.org/api/entityname.csv?fields=:all&paging=false.
The website uses basic authentication. I have manually tested by using the url in a browser and entering the credentials, and everything works fine. I have used the REST connector in a copy activity to download the data as a JSON file (same url, just without the ".csv" in there), and that works fine. But there is something about the authentication in the HTTP connector that is different and causing issues. When I try to execute my copy activity, it downloads a csv file that contains the HTML for the login page on the source website.
While searching, I did come across this Github issue on the docs that suggests that the basic auth header is not initially sent and that may be causing an issue.
As I have it now, the authentication is defined in the linked service. I'm hoping that maybe I can add something to the Additional Headers or Request Body properties of the source in my copy activity to make this work, but I haven't found the right thing yet.
Suggestions of things to try or code samples of a working copy activity using the HTTP connector and basic auth would be much appreciated.
The HTTP connector expects the API to return a 401 Unauthorized response after the initial request. It then responds with the basic auth credentials. If the API doesn't do this, it won't use the credentials provided in the HTTP linked service.
If that is the case, go to the copy activity source, and in the additional headers property add Authorization: Basic followed by the base64 encoded string of username:password. It should look something like this (where the string at the end is the encoded username:password):
Authorization: Basic ZxN0b2njFasdfkVEH1fU2GM=`
It's best if that isn't hard coded into the copy activity but is retrieved from Key Vault and passed as secure input to the copy activity.
I suggest you try to use the REST connector instead of the HTTP one. It supports Basic as authentication type and I have verified it using a test endpoint on HTTPbin.org
Above is the configuration for the REST linked service. Once you have created a dataset connected to this linked service you can include it in you copy activity.
Once the pipeline executes the content of the REST response will be saved in the specified file.

WWW::Mechanize::Chrome capture XHR response

I am using Perl WWW::Mechanize::Chrome to automate a JS heavy website.
In response to a user click the page among many other requests, requests and loads a JSON file using XHR.
Is there some way to save this particular JSON data to a file?
To intercept requests like that, you generally need to use the webRequest API to filter and retrieve specific responses. I do not think you can do that via WWW::Mechanize::Chrome.
WWW::Mechanize::Chrome tries to give you the content of all requests, but Chrome itself does not make the content of XHR requests available ( https://bugs.chromium.org/p/chromium/issues/detail?id=457484 ). So the approach I take in (for example ) Net::Google::Keep is to replay the XHR requests using plain Perl LWP requests by copying the cookies and parameters from the Chrome requests-
Please note that the official support forum for WWW::Mechanize::Chrome is https://perlmonks.org , not StackOverflow.

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

specify response for fiddler core

I use fiddler core to intercept the request and provide a response to it. I know its possible to use saz files to save the response. But the problem is that I need to be able to customize the response. While its a saz file I cant customize the response manually.
Is there a way to save response caught by fiddler to a text file in json like format, so that I could edit it and could serve it as response to any request using fiddler core? For now i see I can save response as a plain text. But how do I load this request to fiddler or parse it with fiddler core to populate all the response properties? Is there some format I could use, that will allow me to manually edit the response?
UPDATE
I see I can just open saz archive, make my edits to reponse and use it to specify the response. Thats exactly what I was looking for. Also there is a way to save response session as har file. Is it possible to save one single response as har/saz file? Currently I can only save session and it contain all requests and responses. Is there a way to limit saved data to 1 request and 1 response?
You have a SAZ file, which contains the full content of a response. Your code may load the SAZ File into FiddlerCore using the Utilities.ReadSessionArchive method. You will then have an array of Session objects.
As FiddlerCore receives requests, you can evaluate whether or not you wish to reply to each request using a previously-loaded response or whether you want to instead let the request flow through to the server. To let the request flow through to the server, do nothing.
To return a previously-generated response, in FiddlerCore 2.4.6.4+ (not yet released), simply call utilAssignResponse on the new Session. For earlier versions of FiddlerCore without this new method, your OnBeforeRequest method should call a method that looks something like this:
public void utilAssignResponse(Session oS, HTTPResponseHeaders oRH, byte[] arrBody)
oS.utilCreateResponseAndBypassServer();
oS.oResponse.headers = (HTTPResponseHeaders)oRH.Clone();
oS.responseBodyBytes = arrBody ?? Utilities.emptyByteArray;
oS.oFlags["x-Fiddler-Generated"] = "Generated by myCode";
}