# How to force users link phone number when they using Discourse?

**URL:** https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642
**Category:** Support
**Created:** [March 26, 2019, 10:54pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642 "2019-03-26T22:54:49Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Lee533](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lee533/32/134468_2.png) [@Lee533](https://meta.discourse.org/u/Lee533)
#### Post date: [March 26, 2019, 10:54pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/1 "2019-03-26T22:54:49Z")

</div>

I’m the admin of a Discourse forum which mainly for China Mainland users, so our the governing law(网络安全法, 互联网跟帖评论服务管理规定 and 互联网论坛社区服务管理规定) required we must use real-name system. That means we must force users link phone number.  
I tried to use Alipay’s API to get user’s phone number, but only their Mini Apps / Programs’ developers can get users’ phone number.  
The main problem is we **must** verify users filed phone number is their real phone number.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [March 27, 2019, 12:46am UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/2 "2019-03-27T00:46:36Z")

</div>

Can you use QQ’s implementation of OAuth2.0?

> **[OAuth2.0简介 — QQ互联WIKI](https://wiki.connect.qq.com/oauth2-0%E7%AE%80%E4%BB%8B)**
>
> QQ登录是QQ互联的一种接入方式，通过接入QQ登录，用户可以使用QQ账号直接登录接入的站点，QQ登录同时提供API授权，帮助网站主将用户操作同步到QQ空间和朋友网；

> [@Discourse OAuth2 Basic](https://meta.discourse.org/t/oauth2-basic-support/33879):
>
> discourse2Summary Discourse OAuth2 Basic supports basic OAuth2 providers, assuming they have a JSON API endpoint where user details can be retrieved by token.open_bookInstall Guide This plugin is bundled with Discourse core. There is no need to install the plugin separately. Features This plugin allows you to use a basic OAuth2 provider as authentication for Discourse. It should work with many providers, with the caveat that they must provide a JSON endpoint for retri…

---

<div class="post-metadata">

### Author: ![Lee533](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lee533/32/134468_2.png) [@Lee533](https://meta.discourse.org/u/Lee533)
#### Post date: [March 27, 2019, 10:55am UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/4 "2019-03-27T10:55:48Z")

</div>

OAuth 2.0 just can allow users Sign In with their QQ account, it can’t get user’s real phone number.

---

<div class="post-metadata">

### Author: ![nexo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nexo/32/106384_2.png) [@nexo](https://meta.discourse.org/u/nexo)
#### Post date: [March 27, 2019, 6:09pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/5 "2019-03-27T18:09:19Z")

</div>

You can create a custom user field asking for a registering user’s phone number and make the field required.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [March 27, 2019, 6:14pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/6 "2019-03-27T18:14:52Z")

</div>

> [@nexo](#):
>
> You can create a custom user field asking for a registering user’s phone number and make the field required.

> [@Lee533](#):
>
> The main problem is we **must** verify users filed phone number is their real phone number.

The emphasis is on **verify**.

---

<div class="post-metadata">

### Author: ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)
#### Post date: [March 28, 2019, 1:22am UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/7 "2019-03-28T01:22:28Z")

</div>

I think the [Facebook Account Kit](https://developers.facebook.com/docs/accountkit/) is a good option for this. I don’t think there’s a discourse plugin for it tough.

---

<div class="post-metadata">

### Author: ![Lee533](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lee533/32/134468_2.png) [@Lee533](https://meta.discourse.org/u/Lee533)
#### Post date: [March 28, 2019, 2:03am UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/8 "2019-03-28T02:03:49Z")

</div>

Thanks, I’ll try it later.

---

<div class="post-metadata">

### Author: ![BobbyZopfan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bobbyzopfan/32/149374_2.png) [@BobbyZopfan](https://meta.discourse.org/u/BobbyZopfan)
#### Post date: [May 16, 2019, 4:14am UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/9 "2019-05-16T04:14:39Z")

</div>

> [@lucasbasquerotto](#):
>
> I think the [Facebook Account Kit](https://developers.facebook.com/docs/accountkit/) is a good option for this. I don’t think there’s a discourse plugin for it tough.

1. Is there any good video tutorial for this? Can you guide me to one?
2. For this to use, do I need to install oAuth 2 plugin?

---

<div class="post-metadata">

### Author: ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)
#### Post date: [May 16, 2019, 12:35pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/10 "2019-05-16T12:35:52Z")

</div>

I haven’t implemented it **for discourse** , so I don’t know exactly how to create a plugin for that, but in my implementation:

**1)** I already had an application in the [Facebook for developers site](https://developers.facebook.com/) (if you don’t have, just create one) and then just added the Account Kit product there.

**2)** Then I loaded the Account Kit script in the front-end:

```html
<script src="https://sdk.accountkit.com/en_US/sdk.js"></script>

<script>		
	AccountKit_OnInteractive = function() {
		AccountKit.init({
			appId: '{{ FACEBOOK_APP_ID }}', 
			state: '{{ CSRF_TOKEN }}', 
			version: 'v1.1',
			fbAppEventsEnabled: true,
		});
	};
</script>

```

(in a first moment, when developing, you can put anything in the csrf token to make the flow work first, then you may return here and handle the csrf token)

**3)** In a button press event from the user I call the javascript SDK:

```javascript
AccountKit.login(
      'PHONE', 
      {countryCode: countryCode, phoneNumber: phoneNumber}, // will use default values if not specified
      loginCallback
    );

```

**4)** The `loginCallback` function calls my backend api in case of success, or shows an error otherwise:

```javascript
function loginCallback(response) {
	if (response.status === "PARTIALLY_AUTHENTICATED") {
		var code = response.code;
		var csrf = response.state;
		callbackSuccess(code, csrf);
	}
	else if (response.status === "NOT_AUTHENTICATED") {
		callbackError("NOT_AUTHENTICATED");
	}
	else if (response.status === "BAD_PARAMS") {
		callbackError("BAD_PARAMS");
	}
}

```

**5)** Then in the backend I call the Account Kit endpoint `https://graph.accountkit.com/v1.1/access_token` passing the code to retrieve the access token, and then I call `https://graph.accountkit.com/v1.1/me` passing the access token to retrieve the phone number (`phone.number`), but first I make sure that it was called using my application Id (created in the 1st step).

> **Click to see the java code that I use (for reference)**
>
> ```java
> public static String retrievePhoneData(String code) throws HTTPException, NotAllowedException {
> String appAccessToken = Arrays.asList(
> "AA", FACEBOOK_APP_ID, ACCOUNT_KIT_APP_SECRET
> ).stream().collect(Collectors.joining("|"));
> 	
> Map<String, String> params = new HashMap<>();
> params.put("grant_type", "authorization_code");
> params.put("code", code);
> params.put("access_token", appAccessToken);
> 	
> SimpleHttpClientRequest requestToken = new SimpleHttpClientRequest();
> requestToken.setMethod(HTTPMethod.GET);
> requestToken.setUrl(TOKEN_EXCHANGE_BASE_URL);
> requestToken.setParametros(params);
> 	
> SimpleHttpClientResponse responseToken = URIUtils.getResponseObjectFromRequest(requestToken);
> 	
> int statusCodeToken = responseToken.getStatusCode();
> 	
> if ((statusCodeToken < 200) || (statusCodeToken > 299)) {
> throw new HTTPException(requestToken, responseToken);
> }
> 	
> String responseStrToken = responseToken.getResponse();
> 	
> Mapper mapperToken = StringUtil.getMapperFromJSON(responseStrToken);
> 	
> String accessToken = mapperToken.getAsString("access_token");
> 	
> SimpleHttpClientRequest requestMain = new SimpleHttpClientRequest();
> requestMain.setMethod(HTTPMethod.GET);
> requestMain.setUrl(ME_ENDPOINT_BASE_URL + "?access_token=" + accessToken);
> 	
> SimpleHttpClientResponse responseMain = URIUtils.getResponseObjectFromRequest(requestMain);
> 	
> int statusCodeMain = responseMain.getStatusCode();
> 	
> if ((statusCodeMain < 200) || (statusCodeMain > 299)) {
> throw new HTTPException(requestMain, responseMain);
> }
> 	
> String responseStrMain = responseMain.getResponse();
> 	
> Mapper mapperMain = StringUtil.getMapperFromJSON(responseStrMain);
> 	
> String appId = mapperMain.getAsString("application.id");
> 	
> if (!FACEBOOK_APP_ID.equals(appId)) {
> throw new NotAllowedException();
> }
> 	
> String phoneNumber = mapperMain.getAsString("phone.number");
> 	
> return phoneNumber;
> }
> 
> ```

I haven’t seen any videos, just followed the steps that is explained here:

[https://developers.facebook.com/docs/accountkit/webjs](https://developers.facebook.com/docs/accountkit/webjs)

(the main change was that it’s in nodejs, and I used java, but it was pretty straightforward, after all it’s just api calls in the backend)

> [@BobbyZopfan](#):
>
> For this to use, do I need to install oAuth 2 plugin?

If you use the javascript flow (including the script that loads the sdk and so on), I don’t think so. But like I said, I haven’t implemented it in a Discourse site, so I don’t know the exact requirements to create a plugin that supports Account Kit.

---

<div class="post-metadata">

### Author: ![BobbyZopfan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bobbyzopfan/32/149374_2.png) [@BobbyZopfan](https://meta.discourse.org/u/BobbyZopfan)
#### Post date: [May 16, 2019, 12:38pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/11 "2019-05-16T12:38:33Z")

</div>

Problem is in the very first step.  
When, after creating our app in the FB developer console, we have to choose components/functions for our app, where we are supposed to find FB Account Kit, there FB Account Kit is no longer there to be found.

 ![image](https://global.discourse-cdn.com/meta/original/3X/e/c/ec26f11f12de12eda5440a3496c9266a1f81c8be.png)

Even clicking on + button besides ‘products’ link, takes us to ‘Dashboard’ screen (as shown in the SS).

---

<div class="post-metadata">

### Author: ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)
#### Post date: [May 16, 2019, 12:55pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/12 "2019-05-16T12:55:32Z")

</div>

I entered my app now and saw that behaviour. To me it seems like a bug on their end. Or you can add the products in another, well hidden place :S

---

<div class="post-metadata">

### Author: ![BobbyZopfan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bobbyzopfan/32/149374_2.png) [@BobbyZopfan](https://meta.discourse.org/u/BobbyZopfan)
#### Post date: [May 16, 2019, 12:56pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/13 "2019-05-16T12:56:37Z")

</div>

> [@lucasbasquerotto](#):
>
> Or you can add the products in another, well hidden place

I can’t find any (option/place/work around)

---

<div class="post-metadata">

### Author: ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)
#### Post date: [May 16, 2019, 12:58pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/14 "2019-05-16T12:58:41Z")

</div>

That was just a joke (because I tried to find in every place and also couldn’t find, so if there is such a place, it must be very well hidden).

I advise to create a question in the Facebook Developers group:

> **[Facebook Developer Community | Facebook](https://www.facebook.com/groups/146797922030397/)**

To make it easier for you, **I already created a post there** (just waiting now).

---

<div class="post-metadata">

### Author: ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)
#### Post date: [May 16, 2019, 1:25pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/15 "2019-05-16T13:25:17Z")

</div>

While they don’t reply, try to see if you can access:

[https://developers.facebook.com/apps/YOUR\_APP\_ID/account-kit/](https://developers.facebook.com/apps/YOUR_APP_ID/account-kit/)

**Update:**

It seems that people created an issue yesterday about it, and it is really a bug:

> **[Meta for Business (formerly Facebook for Business)](https://business.facebook.com/business/loginpage/?next=https%3A%2F%2Fdevelopers.facebook.com%2Fsupport%2Fbugs%2F430289617529755)**

---

<div class="post-metadata">

### Author: ![BobbyZopfan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bobbyzopfan/32/149374_2.png) [@BobbyZopfan](https://meta.discourse.org/u/BobbyZopfan)
#### Post date: [May 16, 2019, 1:45pm UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/16 "2019-05-16T13:45:19Z")

</div>

Wow!!

Love you.  
(not that problems are not there further ahead. But this was a grand step)

---

<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: [December 16, 2022, 3:27am UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/18 "2022-12-16T03:27:15Z")

</div>



---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [January 1, 2023, 4:38am UTC](https://meta.discourse.org/t/how-to-force-users-link-phone-number-when-they-using-discourse/112642/19 "2023-01-01T04:38:17Z")

</div>


