Android App for Rails App storing Sessions/Cookie - android

I am new to both Android and Rails. I built a simple Rails app to log in to post comments and leave replies to others' comments as well. I am trying to see how to build a native Android app to respond to this Rails app and have come across a question with sessions/cookie.
In order for me to build a native android app that can allow a user to log in and browse through the rails app, do I have to write a code that receives cookie from the rails app and store it in android sqlite database? Thanks

Are you trying to load a view in HTML (an embedded browser), or render a view on the device using the native controls? If you're doing the former, surely Android already handles all this for you, just like a WebView in an iPhone app does?
If you're doing the latter, you should build an API that uses something like OAuth for authentication, rather than maintaining a session cookie. This approach means that you store a pair of (revokable) OAuth credentials on the device and that you don't need to work with the user's username/password.
I'm not sure on what your end goal is here.

Related

Mobile app - ASP.NET Core backend server - AWS Cognito authentification?

Please forgive my (perhaps naive) question, I am still a beginner!
I have a website on asp.net core that is essentially a CRUD website. There are some Razor pages and some controllers. When the user is logged in, they can create and update the data they own (through javascript and said controllers).
Login is organised via Cognito's built-in UI. I redirect the user to it with the [Authorize] attribute on certain controller actions. The token (I think this is what it's called?) coming from Cognito is automatically stored in the browser cookie and is passed between the browser and the backend (controllers and Razor pages). In the backend controllers and Razor pages, I have very convenient methods like User.IsAuthenticated(), and can get claims and fetch cognito:username and similar fields.
The website is working well enough.
I am now working on native mobile apps (Android and iOS), and I am wondering how to deal with authorisation in them as well. I want the user to have the same experience in the mobile app as on the website: they would log into the mobile app and see and edit the data they created earlier on the website, and vice versa. I'm not sure how to implement this correctly. I see several options:
Option 1. Use the AWS amplify framework in the apps. I am sure it will work nicely; but how will I then pass the token to my backend controllers? Asp.net core needs it to build this User object, I understand. I think asp.net core stores it in the cookie appropriately named .AspNetCore.Cookies, but I'm not sure as to its format and whether it'll stay stable in the next releases?..
I'm currently reading about JWT bearer tokens, maybe that's the thing that should be used instead of .AspNetCore.Cookies?..
Option 2. I could "pretend" that the mobile app is the same as the browser and send exactly the same requests as my web frontend does. I suppose this sounds very complex - I'd need to store cookies, follow redirects (to the cognito built-in ui, for example) - I don't know if there is a built-in mechanism? However, in this case the app doesn't have anything to do with cognito, talks only with my backend, and is just following redirects. AppAuth states that Authorizing the user occurs via the user's web browser, so perhaps it can be used here?
Perhaps there are other options that I overlooked; I'm almost sure there is a simple solution I just can't see at the moment. Sorry it's all over the place, this is a very new topic for me. Thank you in advance!

Developing both Rails Web App and Android App that shares only one Database

I'm a 3rd year BSIT student who wants to pursue a career of Web Development in the near future. We decided for our thesis to make a Web App about a certain topic using Ruby on Rails since it's the tool that we used during our WebDev class. I've had several experiences and accomplished projects using RoR thanks to the help of this site.
Our Adviser suddenly suggested us to make an Android version of the app for the customer's side to utilize it's portability. what we would like to happen is the Customers can input and retrieve data through that android app from a database, on the other hand, the admin can also do the same using a Desktop Web App utilizing also the the same database used by the customers.
Is there any other recommendations of lightweight development and database tools that can help us make the desired Web App beside Android Studio and Eclipse? Much better if it can support Rails or Ruby.
Note: Also, we're planning to include a GPS feature where you can locate certain shops using the said android app
What you are looking for is an API. You have a Rails app, now you have to expose API endpoints from your Rails App which your Android App can access and send requests to.
I don't know if you learned about APIs yet but in short, you set up new links that retrieve information from the parameters and respond using either JSON or XML. Your android app will for example have a login form:
Name = john
Password = anything
When they submit the form, you take the name and password and send it using an HTTP request from Android to your Rails App.
#stupid example but this is how the link would somehow look like
http://www.your-site.com/api/login?name=john&password=anything
Your rails app should be setup to receive request via an API controller:
class ApiController < ApplicationController
def login
#authenticate user
#respond with json
end
end
Your Android app receives a JSON response from Rails, usually a status code telling Android that the authentication was successful or failed and then you have access to your Web App using Android but nothing is secure and you will have to setup tokens for each request, etc because API's don't have sessions like a browser. But since you are talking about a school project and not a production app maybe you can ignore the security part.
Read this blog post on how to build an API:
https://labs.kollegorna.se/blog/2015/04/build-an-api-now/

json with android mobile application

Hi guys so I am new to android development or any mobile device development.
So I am working on a project that consists of two application.
One with ASP.NET MVC4, one with Android.
what it is doing right now, Android device is accessing database server of ASP.Net application and saves data. This is able because currently, android app has database access information in the codes(db login info).
Since method above is extremely stupid I need help.
So what I am looking into is to use JSON(if possible). ASP.NET MVC4 application is already JSON ready, and i've made sandbox application that brings information from web app to android app. BUT my question here is is it possible to do same thing the other way around. Is it possible to make android application to make JSON and web application to access that application? I dont think this is possible.
So how do other REAL mobile applications save users data on their database server without including db access information within the code?
This is usually done through web api - have a look at twitters api as an example https://dev.twitter.com/docs/api/1.1
You would have to pass data to the server using the api, just as you would use an api to get data from the server.

Ruby on Rails REST API with Android Client that works offline

I am developing a web app on Ruby on Rails and an Android app. They have the same database structure, and now I want to sync the information between both apps. For this I am building a REST API on the rails app.
In the rails app I have devise for authenticating, but for the api I was trying to use doorkeeper which is a oauth2 provider, the problem is that I want to download all the users from the rails app to android app, and I want to give them the possibility to login in an offline mode, they can generate data in the offline mode, and after that, when they get online they will have to sync all the information with the web app. They also can generate data on the web app, so it has to be for both sides, to download information from the web app and to upload information to the web app. How can I achieve this? I have been reading a lot but I haven't found anything similar. I would really appreciate some help.
Sounds like you want to use a SyncAdapter (http://developer.android.com/training/sync-adapters/creating-sync-adapter.html). It supports background downloading/uploading and you can use that for your syncing process.

Sending ASP.NET variable/account information to Android device

I'm using an Android device to display an ASP.NET MVC web application and I was wondering if it's possible to send account information to the android device?
My main goal is to use the users account log-in details to set up a specific save path on the android. If I was able to send the users log-in username to the android device this would be possible.
I'm posting one of the links which deals with this topic extensively (a well written article) http://www.codeproject.com/Articles/304302/Calling-Asp-Net-Webservice-ASMX-From-an-Android-Ap. [NOTE: This solution utilizes the KSOAP library jar for android platform. ]
Basically you would want to have one of the web service methods return the logged-in user, this method can be invoked by Android's native java class.

Categories

Resources