Hello everybody,
I have a solution using service bus who works fine. The client side (by a browser for example) makes a request about a file, and the service side gives the file to the client. This works putting in a browser : 'http://XXX.servicebus.windows.net/Image/GetFile/file.pdf'
and you obtain the file.
Now, I want to add authentication and authorization using Acces Control, so I change the App.config at the service, adding the next:
<security relayClientAuthenticationType="RelayAccessToken"/> in the <webHttpRelayBinding> tag, so now, when you try to get a file, the browser shows you the next message:
<Code>401</Code><Detail>The request contains no authorization header.</Detail>
That's ok.
My problem is next. I added code lines at the client side to obtain a Token using a pair Name/Password, unwrapp the token, and send the token in the header. The code is basically the next:
string returnToken = tf.GetACSToken(name, password, "https://XXX.servicebus.windows.net/Image"); // this URL is the wrap_scope of the authentication
WebClient client = new WebCllient();
client.Headers[HttpRequestHeader.Authorization] = string.Format("WRAP access_token=\"{0}\"", returnToken);
byte[] response = client.DownloadData("https://XXX.servicebus.windows.net/Image/GetFile/hola.pdf");
The code works fine, get the valid token, unwrap the token, insert the header, etc, but when the code execute 'client.DownloadData' an exception ocurrs. With a web debbuger I obtain the next error:
<Error><Code>401</Code><Detail>Invalid token audience: https://XXX.servicebus.windows.net/Image/, expected: http://XXX.servicebus.windows.net/Image/GetFile/hola.pdf.</Detail></Error>
My Access Control Settings are Relying Party Applications with 'https://XXX.servicebus.windows.net/Image' at Realm and Return Url, Token Format as SAML2.0, and a Default Rule Group with a Rule with 'Pass Through'.
I know the error maybe is in use https instead http in the settings, but I tried many changes and I don't find the solution.
Thank you.