Login user via URL token

We are integrating a Unity app with a Meteor backend.

Using unity-ddp, we can successfully authenticate with the Meteor server via DDP, and we’re also able to get the auth token generated for this connection.

In addition to this direct connection, we’ve added a web-view to Unity to show the user interface of the Meteor app as needed. To prevent an additional login, we would like to hand over the auth token we got via DDP to the web view (e.g. via a URL parameter).

Is this possible somehow, with the standard Meteor accounts packages?

I’ve found this separate package, but I’m not sure if this is really needed:

1 Like

I would believe you can pass the auth token to the meteor app, as you said via URL parameter for example, and then parse it in the route controller/function and call Meteor.loginWithToken before rendering the content…

1 Like

In a method:

const stampedLoginToken = Accounts._generateStampedLoginToken();
Accounts._insertLoginToken(user._id, stampedLoginToken);

Then login with Meteor.loginWithToken(token, (err, res) => { })

I suggest:

  1. Create a custom LoginToken in your db once user is logged in or requests the WebView which has an access key and an expiry date. Use this as the URL token.
  2. When logging in via the URL token, check for the LoginToken and if it’s expired. If not, do the above and return the token to the client.
  3. On client call Meteor.loginWithToken with the “real” token you got from _generateStampedLoginToken.
2 Likes

But I wrote a package, Meteor-Unity, that’s so much better… https://github.com/hiddenswitch/Meteor-Unity

It solves your problem and so many more.

2 Likes

That’s awesome. Could not find this earlier. Thanks for sharing!

One question on this, because I cannot find the right spot in the docs: How exactly would your solution help to login a user in Unity and in an embedded web-view at the same time? This is what I was originally asking for.

I can see that the LoginResult returns a login token; but would this token also be accepted by Meteor if I access it via an embedded web browser?

Ah, I see now. You want to share a login token from inside Unity to a web view hosted inside the Unity application, which also visits a meteor website.

Yes. You can simply call the Javascript Meteor.loginWithToken(token, (err, res) => { }) with that token, and you’ll be logged in.

If you’re hosting a web view inside your Unity application anyway, I’d recommend using its internal Meteor connection anyway, by exposing a basic API. It’s relatively easy to proxy objects in Javascript. However, it’s a lot of IT, and if you have something working already, go for it!

I’m using this package :


Working fine :sunglasses:

1 Like

I had a look at this package now. It has quite a number of unresolved issues, with some dating back to 2016. Is this really actively developed? Especially the potential concurrency issue concerns me a bit.

This is actively developed, thanks for your concern.

1 Like

Ok, great to hear that. Thanks for the info.

I‘m currently thinking about an integration where Meteor is also running inside the Unity app (i.e. by integrating the Cordova part of Meteor with Unity). This would give the app some offline capabilities Have you ever considered such an approach?