# Automatic Login from iOS/Android app

**URL:** https://meta.discourse.org/t/automatic-login-from-ios-android-app/48620
**Category:** Support
**Created:** [August 14, 2016, 5:33pm UTC](https://meta.discourse.org/t/automatic-login-from-ios-android-app/48620 "2016-08-14T17:33:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ugo\_Chirico](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ugo_chirico/32/55558_2.png) [@Ugo\_Chirico](https://meta.discourse.org/u/Ugo_Chirico)
#### Post date: [August 14, 2016, 5:33pm UTC](https://meta.discourse.org/t/automatic-login-from-ios-android-app/48620/1 "2016-08-14T17:33:17Z")

</div>

Hi,  
I’m writing an android/iOS app that points to my discourse instance.  
This is the scenario:

1. When the mobile app starts for the first time I create a user on my discourse instance by calling the API by setting active=true. the user should be already active (without needing to activate again it by email)
2. I store username and password in the mobile app after successfull creation.
3. When the app starts I want to automatically login the user to discourse and show him the home page with the login done.

Is there a way to do that?  
How can I do that?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 15, 2016, 12:13am UTC](https://meta.discourse.org/t/automatic-login-from-ios-android-app/48620/2 "2016-08-15T00:13:57Z")

</div>

This is super timely 🙂

See:

> [@User API keys specification](https://meta.discourse.org/t/user-api-keys-specification/48536):
>
> Discourse contains a system for generating API keys per user if a very specific protocol is followed. This feature facilitates “application” access to Discourse instances without needing to involve moderators. High level description At a high level: Client (desktop app, browser plugin, mobile app) generates a private/public key pair and return url Client redirects to a route on discourse giving discourse its public key Discourse gets approval from user to use app Discourse generat…

Working on it this week.

Basically after we generate an API key we redirect to a universal link that your app can open.

**Definately** do not ship API keys in the app, you are 1 jailbreak away from hackers doing whatever they want to your website.

---

<div class="post-metadata">

### Author: ![Ugo\_Chirico](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ugo_chirico/32/55558_2.png) [@Ugo\_Chirico](https://meta.discourse.org/u/Ugo_Chirico)
#### Post date: [August 15, 2016, 8:30am UTC](https://meta.discourse.org/t/automatic-login-from-ios-android-app/48620/4 "2016-08-15T08:30:47Z")

</div>

Hi Sam,

this features seems really interesting.

I read your suggested post. I’m in use case 2: Mobile applications that poll Discourse sites on behalf of end users and handles push notifications.

But I don’t understand how to use this new feature in my app.

These are my requirements:

1. I put in the app a WebView that displays my discourse instance as is (I don’t want to write an app from scratch by using the API like the one I saw on GitHub);
2. The first time the app starts I create a new user linked to the user’s mobile phone ID. The user must be active i.e. no needs for confirmation email;
3. I store username and password (and any other info and keys) in the app memory (in the sandbox);
4. From now on every time the app starts the WebView must show my discourse instance already logged in using stored username and passwor, i.e. I don’t want to show the login panel to the user every time he runs the app.

Can you explain me how to use it in my app to satisfy my requirements?

BTW I know that API keys must not shipped in the app. There are several ways to avoid from that 😉

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 16, 2021, 8:27am UTC](https://meta.discourse.org/t/automatic-login-from-ios-android-app/48620/8 "2021-04-16T08:27:58Z")

</div>



---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [April 19, 2021, 1:20am UTC](https://meta.discourse.org/t/automatic-login-from-ios-android-app/48620/9 "2021-04-19T01:20:14Z")

</div>


