Custom Login Handler meteor 1.4

Hi there,

I’m trying to make a custom authentication that relies on a REST API call.
All the messages I read dealing about this are out dated or undocumented and I didn’t succeed in making them work (for example Accounts.callLoginMethod doesn’t seem to exist any more).

I tried an approach that :

  • creates a server side method calling the api with login/password and returning a connection token. It modifies the user document of the User collection to gather connection infos, and set the userId.
  • call the server side method and set the userId from the client side

But it doesn’t work as expected : refreshing a page make my connection lost.

What is the actual and good way to do ?

Server :

   private getConnexionInfo(username: string, password: string): any{
        let url: string = + '/' + this.api.endpoints.token;
        let params: HTTP.HTTPRequest = {
            data: { username: username, password: password },
            headers: { 'Content-Type': 'application/json' }
        let result;
        try {
            result =, params);
        } catch (e) {
            return null;

      private recordUserToMongo(token:string, username:string, mail:string, lastname:string, firstname:string){
        let now = new Date();
        Users.upsert(username, { $setOnInsert: { createdAt: now, emails:[{adress:mail, verified:true}], 
                                                 lastname:lastname, firstname:firstname}, 
                                 $set: { services:{ resume:{ loginTokens:[{when:now, hashedToken:token}]}} } });

    disconnect(username: string){
        console.log("Disconnect "+username);
        Users.update(username, { $unset: { services:"" }});

    connect(username: string, password: string): string {
        let infos = this.getConnexionInfo(username, password);

        if (infos !== null) {
            this.recordUserToMongo(infos.token, username, infos.mail, infos.givenName,;
            return infos.token;
            return null;

Client side :

        let log ='connect', username, pass);
        if (log !== null){
            this.user = Meteor.userId();

Thanks for your help !

Accounts.callLoginMethod does still exist.

Are you trying to write an Oauth client?

Thanks for your reply !

Maybe have I miss something about Accounts.callLoginMethod. It doesn’t compile. I’m gonna look forward.

I’m not writing and Oauth client : as it is for an internal need, authentication is done via an api that a custom token system.

1 Like

Yes, I am, but I’m also using typescript. I don’t see this method defined in the index.d.ts for accounts-base.

@fabbio35 did you ever figure this out?

What I did is modified the index.d.ts file under node_modules/@types/meteor and modified the last line to include that call (right with any but can make specific types when I have more time):

declare module "meteor/accounts-base" {
    module Accounts {
        function onLogout(func: (user: Meteor.User, connection: Meteor.Connection) => void): void;
        function callLoginMethod({methodArguments: any, validateResult:any, userCallback: any}): void;