How to get user id with OAuth access token?

I have created an OAuth client and obtained an OAuth access token according to the documentation Authentication | The Things Stack for LoRaWAN .

Is it possible to get collaborator.user_ids.user_id using OAuth access token?

This user id is needed for creating new gateway with GatewayRegistry service Gateway APIs | The Things Stack for LoRaWAN

Try this:

https://www.thethingsindustries.com/docs/reference/api/user/

How can I use User APIs to obtain user_id from OAuth access token?

I have found UserRegistry.Get method, but it requires user_ids.user_id, and I don’t have it.

Maybe, it is possible to decode OAuth access token and get user_id from it?

There is no user_id in the OAuth access token - it provides authorisation to act within the scope that you requested in the setup of the OAuth Client Registration:

https://www.thethingsindustries.com/docs/reference/api/authentication/#oauth-access-tokens

So the user provides their user id but you can validate that against the UserRegistry

Do you the a particular use case that requires OAuth? The implied recommendation are the API keys.

I want to create a mobile phone application, that allows users to manage their TTN entities (gateways, applications, devices).

To achieve this a user clicks “Login with TTN” button on the application side.

Using OAuth 2 protocol, the user enters his credentials on the TTN side and my application obtains access_token and refresh_token.

Using access_token, I want to use GatewayRegistry service to create gateway.

The URL path for this method (POST /api/v3/users/{collaborator.user_ids.user_id}/gateways) contains collaborator.user_ids.user_id, but I haven’t it’s value.

So my current goal, to obtain the value of collaborator.user_ids.user_id somehow.

I have found https://eu1.cloud.thethings.network/oauth/api/me endpoint for fetching information about a user. For example:

{
    "user": {
        "ids": {
             "user_id": "..."
         },
        "created_at": "...",
        "updated_at": "...",
        "state": "..."
     },
    "logged_in_at": "..."
}

But, as I understand, it uses cookies for authentication.

Is it possible to use this API endpoint with API key or OAuth access token?

I believe the scheme is all about the user entering their user id at some point in the flow - I haven’t got to implementing OAuth on this platform yet.

Yes, user enters his credentials during OAuth flow.

But he does it on TTN side. They are not accessible to external app (in my case - mobile application).

I can ask user to log-in to his TTN console and copy his user_id. Then he can paste it to my application.

But I try to automate manual steps, so it will be easier for user to integrate my application with TTN.