Reputation: 663
I have a Wcf web service and an android application that makes calls to the service methods. It is a requirement that some sort of authentication take place, preferably with a username/password combo. The data is not sensitive but I just need to make the service only accessible from the android application. Any help is greatly appreciated.
I have multiple methods very similar to this
<OperationContract()> _
<WebInvoke(Method:="GET", ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.WrappedResponse, UriTemplate:="endpoint?busUnit={busUnit}")> _
Function lstJobsSVC(busUnit As String) As List(Of JobsView)
Then I implement the method in the service as follows
Public Function lstJobsSVC(busUnit As String) As List(Of JobsView) Implements IService1.lstJobsSVC
Dim entities As New RemoteTimeEntities()
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"
Return entities.lstJobs(busUnit).ToList
End Function
And then in android
URL json = new URL("http://localhost/json/Service1.svc/"+ "functions endpoint";
HttpURLConnection jc = (HttpURLConnection) json.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
readLine = reader.readLine();
JSONObject jsonResponse = new JSONObject(readLine);
JSONArray jsonArray = jsonResponse.getJSONArray("get json array name");
Now All of this code works fine I just do not understand how to implement authentication that will work between the two.
Upvotes: 0
Views: 1523
Reputation: 8866
I assume you got the calls itself working correctly. If so, the simplest (yet secure enough) method to authenticate clients would be:
This method requires an SSL connection to be fully secure (to protect against eavesdropping/replay attacks)
If you need to restrict the data to android app only, you need to encrypt the payload with the AES key known only by both server and client applications. Use only CBC or CTR modes.
You can combine both methods if needed. But keep in mind that security is a very tough matter, and the approaches I've described are only "so good". Don't put confidential info in the app, if you don't know exactly what you're doing.
Upvotes: 1