Invitation based authentication for Meteor - AuthentiqID/meteor-accounts-authentiq GitHub Wiki
The following enables Authentiq with invitation based authentication for Meteor.
Installation
meteor add accounts-ui service-configuration authentiqid:accounts-authentiq
Configure Authentiq package
On the server side add the following code:
ServiceConfiguration.configurations.remove({ service: 'authentiq' });
ServiceConfiguration.configurations.insert({
service: 'authentiq',
clientId: '{YOUR_AUTHENTIQ_CLIENT_ID}',
clientSecret: '{YOUR_AUTHENTIQ_CLIENT_SECRET}'
});
Disallow account sign up
To avoid people registering new accounts, add the following configuration for both server and client.
Accounts.config({
forbidClientAccountCreation : true,
sendVerificationEmail: true // makes sense if you allow username & password logins
})
On the server side this will disallow user registration if called from browser console like
Accounts.createUser({username:'test', password:'1234', email:'[email protected]'})
On the client side it will remove the sign-up button from accounts-ui, if
Invite new users
There is a variety of solutions in the community, each with their own strengths. Described here is just one example that worked well.
Example
Install this package meteor add t3db0t:accounts-invite.
Then, on the server side, do:
// server
AccountsInvite.register({
validateToken: validateToken,
onCreatedAccount: onCreatedAccount
});
function validateToken(token){
if(InvitesCollection.findOne({"token":token})) return true;
else return false;
}
function onCreatedAccount(token, user){
InvitesCollection.update({"token":token}, {$set:{"status":"claimed"}});
// Here you could also do something like...
// Roles.addUsersToRoles(user._id, ['beta-permissions']);
}
To verify, visit your site and:
-
Try to login with Authentiq.
-
If user doesn't exist then the login will be disallowed.
-
Now activate the account by confirming the invitation. In your browser console run:
Meteor.loginWithInvite({inviteToken: 'test_token'}, function(error){ if (error) console.error(error); }); -
Now try to login again with Authentiq and same user as in step 1.
-
A new user has been created.
Here is a nice tutorial for achieving the above notes.
Account merging
If a user signs in with Authentiq and Google using the same verified email address then we'd like that to result in a single user in our database, and not two. Again there are many ways and packages you can use to achieve this, the one we install here is just a suggestion.
Install this package
meteor add splendido:accounts-meld
You can read more on its documentation.
Pending commit
The accounts-meld package requires a change in the meteor-accounts-emails-field package to work with Authentiq. Until the linked pull request is accepted, here is how you can use it in your application already.
Get code from Github somewhere in your machine:
git clone [email protected]:ziogaschr/meteor-accounts-emails-field.git
cd meteor-accounts-emails-field
git checkout check-email-verified-openid
Go to your app folder and do:
mkdir -p packages
ln -s /path/to/meteor-accounts-emails-field packages/splendido:accounts-emails-field
meteor add splendido:accounts-emails-field
If you already installed the accounts-meld package then re-run meteor add splendido:accounts-meld.