Search code examples
authenticationflask-securityflask-mongoengine

Flask-Security - Username to generate auth token instead of email


I am developing an application using Flask and using Flask-security for token based authentication feature. I developed a prototype code looking at docs and different examples I could find on internet. I see 'email' field is required to get a auth token. But I need 'username' field instead. I tried changing 'email' to 'username' attribute in the user model but it throws an error while requesting for the auth token - "Email not provided"

Is there some config flag that I am missing?

FYI, I am using MongoEngineUserDataStore

Thanks


Solution

  • Use SECURITY_USER_IDENTITY_ATTRIBUTES = ['username']

    From the docs :

    Specifies which attributes of the user object can be used for login. Defaults to ['email'].