Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register using social auth #751

Open
TimotheeJeannin opened this issue Feb 14, 2023 · 2 comments
Open

Register using social auth #751

TimotheeJeannin opened this issue Feb 14, 2023 · 2 comments

Comments

@TimotheeJeannin
Copy link

Hi,

It's great that social auth is supported but it would be awesome if users could register with social auth too.

I think most websites that support social auth also support it for registration.

Tim

@ademaro
Copy link
Contributor

ademaro commented Mar 2, 2023

@TimotheeJeannin, hi!

So you can implement it in your application any way you want. I don't think it should be part of the flask-security.

Here's a little example:

@anonymous_user_required
@core.route("/auth/<name>")
def auth(name):
    client = oauth.create_client(name)
    if not client:
        abort(404)

    client.authorize_access_token()
    profile = client.userinfo()
    user = lookup_identity(profile["email"])  # Check if there is already such a user with this email
    if not user:
        user_datastore.create_user(email=profile["email"], is_active=True)  # Create (register) a new user
        user_datastore.commit()  # Updating the database with a new user
    login_user(user)
    user_datastore.commit()  # Updating the database for capturing the time of login
    return redirect(url_for("route_fn_for_user_dashboard"))

@chrisroat
Copy link

I think this is a great idea.

One important piece to consider is that the oauth dance returns an email, while the app may have a much more detailed User model with additional fields. So there will be missing fields in the oauth registrations, which a form-based registration would capture.

I believe the addition of an update-user-info endpoint would mitigate this issue. It would exist whenever the user model contains extra fields. It would serve two uses:

  • any logged in user can update the extra fields by going to the endpoint
  • if oauth registration is enabled, the user would be redirected to the endpoint to finish registration (if there are extra fields to be filled in)

Does this sound reasonable? Does it miss any cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants