Skip to content
This repository has been archived by the owner on Oct 25, 2018. It is now read-only.

4. Connecting to Server with OAuth

Azri Azmi (Aba) edited this page May 13, 2015 · 2 revisions

By now you may be wondering, "Finally..it's ready." Not just yet. You'll need to set up the SpaceScout Spotseeker backend (for development purposes, we use the dev build), which is in Python-Django. This wiki article assumes that you have done so; else, follow the link provided. Once you have the backend ready, you can proceed.

##Configure OAuth on Spotseeker Server SpaceScout currently uses OAuth1.0a for apps to connect to it. If you just created your dev/virtual server, you can go to 'spacescout > spacescout_builds > server_proj > server_proj > local_settings.py' and observe that the default for the authentication setting is

SPOTSEEKER_AUTH_MODULE = 'spotseeker_server.auth.all_ok'

This allows for apps to directly connect to the server. For OAuth to be implemented, it should be changed to

SPOTSEEKER_AUTH_MODULE = 'spotseeker_server.auth.oauth'

##Get your Consumer Key & Secret In your Spotseeker server, create your OAuth "consumer" by using the following command (virtualenv should be active):

./manage.py create_consumer

Input any name you'd like in the prompt and you will receive a key and secret.

If you get an error, most probably it's because you installed "oauth_provider", which conflicts with the oauth provider listed in requirements.txt. Just remove everything in 'lib/python2.7/site-packages/' and reinstall everything in requirements.txt.

To check your key, follow the steps below:

./manage.py shell
from oauth_provider.models import Consumer
a = Consumer.objects.all()
a[0].key
a[0].secret
a.values() //lists out all of Consumer's objects

The above provides you with the first key/secret in the dictionary.

##Adding the Key and Secret in Android In your gitignored 'SpaceScout/src/main/res/values/secrets.xml', place your key and secret as follows (key/secret below is fake):

<string name="consumerKey">23k4k1k09470c6d2ff23665bf588fb91773bnm65</string>
<string name="consumerSecret">m67jkace11b5cfc004e7fb1d6321f92ca7e0980a</string>

You may observe that the string resource above is called in "SpaceScout > java > JSONParser.java" in the following code:

...

public JSONArray getJSONFromUrl(String url){
    OAuthConsumer consumer = new CommonsHttpOAuthConsumer(
            appContext.getResources().getString(R.string.consumerKey),
            appContext.getResources().getString(R.string.consumerSecret));

...

##Add the URL of the Spotseeker Server Create a file called "secrets.xml" in 'SpaceScout/src/main/res/values/'. Don't add this file to version control if prompted. It should also be gitignored. Add your Spotseeker server URL as such:

    <string name="urlAll">http://dnsname:8000/api/v1/spot/all</string>
    <string name="baseUrl">http://dnsname:8000/api/v1/</string>

Where "dnsname" is your DNS name (i.e. apples.eplt.oranges.edu) followed by the port number you run your virtual server on. 'urlAll' is only to be used for dev purposes.

##Runserver Before you run your app on you AVD, be sure to run the spotseeker server from the 'server_proj' dir in Terminal

 ./manage.py runserver 0:8000

Using "0" instead of "localhost" or "127.0.0.1" enables the AVD to contact the server. Now, you may run the app. :)

You can observe the requests made by the app on the Terminal screen running the server. If a 401 error occurs, try checking if your key & secret matches between the app & server. If you don't see any requests made, check the URL in your xml file.

Clone this wiki locally