Oauth with iOS and android together with Symfony2

In a few projects I made in the last few months I wanted to use a method to login at a custom site within a app on Android or iOS. Using the username/password combination from the website itself didn’t seem to be a great idea, so that was scrapped directly.

I decided to look into using oAuth2 for accessing the API that was created on the website for authorisation. oAuth2 seems to be a commonly used, by companies like Google, Facebook and GitHub. Searching for simple implementation for both Android and iOS showed a few libraries, but all of them weren’t documented that well.

With this serie of blog posts I am going to try making a simple example website that contains a simple REST API written in symfony 2. This API will be called with 2 apps, 1 iOS app and 1 Android app. These apps are very simple, and have no other features/usages within this example. They are created just to show how to integrate the oAuth2 part into a app.

All code by used within this serie will be published at github, see the specific posts for the repository for that part of the project. The project is split up in 3 separate repositories.
While this project is ment to be a example for creating oAuth authorization, I still assume you have basic knowledge about both Symfony2, as iOS and Android programming. I won’t be explaining how to create a basic project for these three setup. All exampled that I publish are working and tested examples.

This serie is split up in more then one blogpost, in every blogpost I try to concentrate myself on one component in this project. Due too time constraints I won’t be able to publish all posts directly from the start, I will try to publish a post once every week.

In case of questions/mistakes/spelling errors/etc/ please leave a comment on the specific blog post. I will try to answer them as soon as possible.

3 thoughts on “Oauth with iOS and android together with Symfony2

  1. Hi Paul,

    thanks for the tutorial.

    Your demo app from Google Play actually throws an error “ContextErrorException […]”.
    I wanted to test it because I got stuck at the android part.

    I managed to get the symfony part work on my test server, but after spending hours trying to get Android Studio working properly, I will soon give up. Whatever I do, I cannot select a virtual device where to run the app on. In my oppinion the usage of Android Studio is much more difficult to understand and it’s a pain to configure it in comparison to Eclipse ADT, which I managed to install and configure in a few minutes. Because the project contains “.idea” directories, I thought it might be easier to use Android Studio for following your tutorial. I do not have experience with both IDEs as I’m a beginner in the “java world”.

    I created a VM and can start it via the SDK AVD Manager. Don’t know what’s missing in my Android Studio configuration. Can you please publish your exported Android Studio settings or explain the necessary steps more detailed?
    What is more – I have absolutely no idea how to handle the “gradlew” thing. Never heard of it before… After cloning your repo from github a file gradlew.bat exists in my project directory. My understanding is that executing it downloaded some missing dependencies and that seemed to have worked.

    Maybe you can explain to beginners how to import the project and get it running step-by-step.

    Thank you!

    1. I just fixed the demo, there was a small permission issue with the symfony install.

      It looks like the current files in the GIT repo doesn’t work with the latest android studio.

      If you are importing the project into android studio, you should have at the top in the bar a green arrow. If you click on here, you should get after a while the option on which device you want to run the app. Within this screen you also have the option to create a new emulator (The button with …) if you have no android device connected. Booting up the emulator can take a bit, but after a while you see a screen with android being started.

      Importing it into android studio can best be done directly via github in android studio by choosing VCS -> export from version control -> github.

  2. Hi Paul,

    thank you for the reply! I tried to continue by using your suggestions but could not achieve any progress. Please keep in mind that I tried to follow your tutorial starting with a “clean” windows system, that means I have never before used or configured Android Studio or its requirements on the system.

    This is what I did so far:

    I installed the latest Java 8 JDK Update 25 and set JAVA_HOME to the JDK’s path.

    Then I downloaded Android Studio 0.5.2 from http://tools.android.com/download/studio/canary/0-5-2

    I extracted the archive’s content to d:\android-studio

    When I first tried version 0.8.x (it was offered to me to download by default), I could not even find out how to tell Android Studio which Android SDK to use. There are lot of differences between 0.5.x and 0.8.x, and 0.8.x for me seems to be even much more complicated to be configured…
    So I installed 0.5.2.

    After that, I downloaded Android SDK from https://developer.android.com/sdk/index.html

    I installed the SDK to d:\android-sdk

    Then I started “d:\android-sdk\SDK Manager.exe” as Administrator (I had problems creating/updating paths when starting it without Admin rights).
    I installed:

    Tools/Android SDK Tools (Rev. 23.0.2)
    Tools/Android SDK Platform-tools (Rev. 21)
    Tools/Android SDK Build-tools (Rev. 21.1.1)
    Android 5.0 (API 21)
    -> all sub elements
    Extras/Android Support Repository (Rev. 9)
    Extras/Android Support Library (Rev. 21.0.2)
    Extras/Google Play services (Rev. 21)
    Extras/Google Repository (Rev. 13)
    Extras/Google USB Driver (Rev. 11)

    Then I installed Git for Windows from https://windows.github.com

    After a restart of the computer (surely not required but anyway…), I opened Android Studio (d:\android-studio\studio64.exe)
    Because this was the first start I was asked whether to import existing settings (if available) or not. I answered “I do not have…”. Maybe you could export your Android Studio settings so that I can import them or at least compare them with my settings to see what I am missing 🙂

    Next, I entered the path to git executable in “Configure / Settings / Version Control / Git” (C:\Users\MeMyselfAndI\AppData\Local\GitHub\PortableGit_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\bin\git.exe)
    Clicking “Test” says git was successfully executed.

    Back at the “Welcome to Android Studio” screen I clicked “Check out from Version Control” and selected “Git”. I choosed “Git” because “GitHub” would require me to enter either username/password or a token, and I have none of them. For “Git” it’s enough to enter the URL “https://github.com/paul999/AndroidOauthDemo.git”.
    After cloning the files successfully to d:\AndroidOAuthDemo, Android Studio asked whether to open the checked out project.

    I answered “Yes”.

    After the files were loaded, I entered “Alt” + “1” to enter “Project files” view.
    The “Run” Icon (I think that is what you ment by “green arrow top in the bar” in your answer) is greyed out. Clicking “Run / Run…” from the main menu shows me a small window “0. Edit Configurations…”. Clicking on it opens another window “Run/Debug Configurations”. There is a “Defaults” configuration with a “Android Tests” sub page where I can enter which “Emulator” to use. Clicking the icon with the 3 dots opens “AVD Manager”. AVD Manager opened and I created a simple AVD (AVD Name = “VM”) and started it. But whatever I do, the damn dropdown menu “Prefer Android Virtual Device” stays empty, I cannot select anything. Restart of Android Studio while the AVD is running did not help, the list is still empty.

    This is where the awfulness of Android Studio begins and my knowledge ends… Do I need to “Add New Configuration”, and if so – which of the thousands of available options are definitely required to be set?!

    In comparison to Eclipse ADT Bundle the default config of Android Studio is terrible! Eclipse ADT Bundle is much simpler to be set up for the first start. I even managed to get a “Hello World” test app installed on my (rooted) Smartphone.
    But as I want to learn to develop Android Apps and a lot of developers recommend “Android Studio”, I want to give it a try.

    I would be very grateful if you could help me. I don’t think I’m missing much. I’m sure there are only few things still missing in my configuration.

    Thank you and best regards

Leave a Reply

Your email address will not be published. Required fields are marked *