Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Login authentification without Parse

Hello guys!

I'm following the Android development course. The login authentification with Parse is really simple but actually, I don't need it because I already have a website with thousands of users.

I don't want to reinvent the wheel, do you have some examples of "UserClass" I can use to achieve login with my website (php) ?

First, I would like to do a Basic auth while i'm the only one to use my custom api. The views don't change from the "Build a Self-Destructing Message Android App". I just have to change the login and logout function.

I figure I just do an async httpconnection. I post my login and password with POST data. I retrieve a json with success or error. If success, how can I keep the connection when I load different activities ? I have to check the connection every time ? Or do we have like sessions in Android/Java ? Is it enough secured ?

In order to give access to my api, my other idea was to intent a webview with the login url like http://www.mywebsite.com/api/login On this page, a simple form where the user enters his login and password (java can't access the content in the webview right? I don't want a third party application to catch my password). But how the android app will know when the authentification succeed and maybe catch a token for next calls ?

If you have some documentation or guidances to look for, thank you ;)

2 Answers

Fair enough,

Have a look at Retrofit: http://square.github.io/retrofit/

This is far and away the easiest way to implement networking in your android apps, in my opinion. You can create various interfaces, which you then create instances of to make your api calls. It has a very clear and easy to use Callback that is provided to you, and as such you can get at, and manipulate your response data ( and if you specify in the interface what <type> you want the data to be, it will automatically parse it from JSON to POJO's for you.

Thanks! I will try this tonight.

It's perfect! As you said, easy to implement. You save me a lot of time! Just to do the Basic Auth on my api and I'm good.

In general, you could get your API to provide a token or cookie upon proper login, and then utilize that token on all your subsequent API calls. Check with the guy who did your API, i am sure there is some sort of provision for a token.

I'm the guy :) The API doesn't exist yet. So I can do what I want, it's the android part that worries me.