简体   繁体   中英

Oauth login and registration with custom username, express.js

I use node.js+express.js stack, users can reigster/login with twitter and facebook, and also can register with my native registration form. I use everyauth to handle with Twee and Fb.

The question is: Is there a simple solution to register users with third-party oauth services while allowing them to change it's username?

example: User logins to site with twitter first time -> he gets form where he adds his CUSTOM USERNAME and email .

While he logins next time I need to check in db his CUSTOM USERNAME and not his twitter one.

Yes it is possible. On first login attempt you authenticate the user via twitter using the node-oauth module. Here's a tutorial . After the authentication process is done, twitter sends a unique ID in its results, you store that with oauth token and secret (if you want to) inside your DB. Also save these data in Session and show a form where you ask for the user to choose a username of his wish. Use that and store in DB.

Next time, when he tries to authenticate again, you just check against the unique ID stored in your database (not the username really).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM