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

Oauth username provider suffix added #17780

Closed
wants to merge 3 commits into from
Closed

Conversation

asSqr
Copy link
Contributor

@asSqr asSqr commented Nov 23, 2021

I implement the issue #7014.

In preparation for introducing the second login source, usernames should be namespace-wise. The suffix "-{provider}" will be added automatically.

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (main@d0a681f). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17780   +/-   ##
=======================================
  Coverage        ?   45.54%           
=======================================
  Files           ?      808           
  Lines           ?    89969           
  Branches        ?        0           
=======================================
  Hits            ?    40975           
  Misses          ?    42449           
  Partials        ?     6545           
Impacted Files Coverage Δ
routers/web/user/auth.go 12.06% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d0a681f...f19cee5. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 23, 2021
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Nov 23, 2021

  1. It breaks existing users (they won't be able to login as their original username)
  2. Some users may not want that suffix
  3. If some providers are deleted or renamed, how to handle existing users.

@asSqr
Copy link
Contributor Author

asSqr commented Nov 23, 2021

we create the provider db table and the namespace field representing the provider in the user model → If some providers are modified, we have only to update the provider table. Or if deleted, we fetch all users with that provider and delete them.

This strategy seems good.

@asSqr
Copy link
Contributor Author

asSqr commented Nov 23, 2021

I have implemented the above comment. I'm sorry that I have made a trivial mistake and bother you.

if err != nil {
return nil, err
} else if !has {
return nil, ErrUserNotExist{id, "", 0}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ErrUserNotExist Wrong error to give here.

db.RegisterModel(new(OAuth))
}

func getOAuthByID(e db.Engine, id int64) (*OAuth, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These function is essentially deadcode as it isn't used other than GetOAuthByID which on itself isn't used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General note, a lot of dead code functions are in these files...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have the table, why should we create a new one?


func getOAuthByName(e db.Engine, name string) (*OAuth, error) {
if len(name) == 0 {
return nil, ErrUserNotExist{0, name, 0}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto wrong error.

if err != nil {
return nil, err
} else if !has {
return nil, ErrUserNotExist{0, name, 0}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto wrong error.

@@ -162,6 +162,9 @@ type User struct {
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
Theme string `xorm:"NOT NULL DEFAULT ''"`
KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"`

// OAuth
OAuthProvider int64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
OAuthProvider int64
OAuthProviderID int64

You will also need a migration for this - as existing users won't have any.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an external_account table, I think it's already ready.

@@ -649,14 +649,28 @@ func SignInOAuthCallback(ctx *context.Context) {
ctx.ServerError("CreateUser", err)
return
}

oauthProviderName := strings.ToLower(provider)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this actually?

This adds the name of the oauth into a new database table, link within the user to the ID of that oauth. But that doesn't solve the issue of adding a suffix.

Also, we already have this, look at the LoginSource field ;) which should give you the same way of getting the Oauth's name.

@@ -0,0 +1,125 @@
package models
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright head missing

Copy link
Member

@lunny lunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of them have been implement

@@ -162,6 +162,9 @@ type User struct {
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
Theme string `xorm:"NOT NULL DEFAULT ''"`
KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"`

// OAuth
OAuthProvider int64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an external_account table, I think it's already ready.

@stale
Copy link

stale bot commented Apr 30, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions.

@stale stale bot added the issue/stale label Apr 30, 2022
@yardenshoham
Copy link
Member

This is in progress for a while now, I'm closing it to avoid stale pull requests. Please reopen when it's ready for review.

@go-gitea go-gitea locked as resolved and limited conversation to collaborators Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/stale lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants