Skip to content

Expect personal access token in password field, not username field#6421

Closed
bmgxyz wants to merge 1 commit intogogs:mainfrom
bmgxyz:issue-3866-personal-access-tokens
Closed

Expect personal access token in password field, not username field#6421
bmgxyz wants to merge 1 commit intogogs:mainfrom
bmgxyz:issue-3866-personal-access-tokens

Conversation

@bmgxyz
Copy link

@bmgxyz bmgxyz commented Nov 17, 2020

Fixes #3866

Users with 2FA enabled rely on personal access tokens to authenticate on the command line. Gogs supports this feature, but the implementation expects the user to enter their token in the username field and leave the password field blank. This is poor security because the token is meant to be a secret, but neither Git nor Gogs treat the contents of the username field as a secret.

This small change fixes this behavior by expecting the user to input their username in the username field and their personal access token in the password field. The authentication attempt only succeeds if both fields are correct. Note that this is the behavior on GitHub, as far as I can tell.

I'm quite new to Go, so I welcome any edits or suggestions.

Also, check to make sure that the username input matches the user
associated with the token.
@PetervdPerk
Copy link

Great contribution, was trying configure my gogs server to let it behave like Github 2FA but it seems it's not a configuration issue but more an implementation issue.

Is there any reason why is isn't in upstream yet, who are the maintainers of this project I see @unknwon is approving pull requests.

Copy link
Member

@unknwon unknwon left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

This is a great improvement, but also introduces break changes, i.e. people are relying on passing access token via username field is now failing.

I think we should support passing access token in both fields for backward compatibility.

@unknwon
Copy link
Member

unknwon commented Oct 22, 2022

Superseded by #7198.

@unknwon unknwon closed this Oct 22, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use personal access tokens as password

3 participants