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

Token deploy prompts for username #159

Open
oliversturm opened this issue Jan 8, 2020 · 16 comments
Open

Token deploy prompts for username #159

oliversturm opened this issue Jan 8, 2020 · 16 comments

Comments

@oliversturm
Copy link

I'm trying to deploy my hexo site to GitHub Pages. Right now I'm testing my setup locally, but I intend to use a CI setup once it works (probably using GitHub actions).

Based on the README, I included this block in my _config.yml:

deploy:
  type: git
  repo: https://github.com/<myusername>/<myrepo>.git
  branch: gh-pages
  token: $GITHUB_TOKEN
  name: <my "visible" name>
  email: <my email>

I created an access token in GitHub with the repo scope. Now I run the deployment from the command line to test it:

GITHUB_TOKEN=<my token> hexo deploy

The site is generated and I see git messages when everything is added to the new local repo. After this, I see a prompt:

Username for 'https://github.com': 

Why does this come up? Who is supposed to enter this username in a CI scenario? My local system is not configured to remember an HTTPS GitHub username, since I normally use SSH. But the CI system would obviously never know this username - how do I specify it?

(I tried using the name setting in the config file as a test, but that doesn't work - looking at the code, it's clearly not intended for that purpose.)

I confirmed that if I enter the username manually, the password prompt appears next. At this point I have to enter the token again and everything works - but it appears that the token configuration in the config file is ignored entirely.

I'm sure I'm misunderstanding something... can anybody confirm that token deployment is supposed to work for my use case?

@oliversturm
Copy link
Author

Update: I was looking at https://hexo.io/docs/one-command-deployment.html and I found this.

You will be prompted with username and password of the target repository, unless you authenticate with a token or ssh key.

This is clear enough - I should not expect a prompt when using a token. Does that mean something is wrong with my configuration for the token, or the mechanism that reads it?

@SukkaW
Copy link
Member

SukkaW commented Jan 8, 2020

@oliversturm

export GITHUB_TOKEN=<token>

Will it work?

@oliversturm
Copy link
Author

@SukkaW That shouldn't be necessary - the syntax I'm using sets the environment variable without exporting it. Works like a charm, usually.

On the suspicion that the environment variable value is not found for some reason, I tried adding my token to _config.yml directly, but this doesn't change anything about the behavior I'm seeing.

@oliversturm
Copy link
Author

So... reading the source code, I find that the token handling is exclusively implemented in this function. As far as I can see, this means that it can only be used with the config structure that has a repo object with a sub-property url - the other syntax variations use other execution paths that don't handle the token at all. How strange.

I'll try to change my config and update this issue.

@oliversturm
Copy link
Author

With a different config structure it works correctly now:

deploy:
  type: git
  repo:
    github:
      url: https://github.com/<myusername>/<myrepo>.git
      branch: gh-pages
      token: $GITHUB_TOKEN
  name: <my "visible" name>
  email: <my email>

I'm leaving the issue open - I guess this should either be fixed in code or documented.

At this point I'm only wondering how everybody else does this? I wouldn't normally use this config structure unless I was pushing to multiple repos, which seems like an edge case to me.

@PinkyJie
Copy link

Thanks @oliversturm, I was stuck for the same issue for hours, finally it was solved by your solution!

@tienhm0202
Copy link

Thanks @oliversturm. I do believe this need an document update. As you said, it's not common case

@carlos-algms
Copy link

The @oliversturm solution does not work for me 😞
I'm getting an error about password:

fatal: could not read Password for 'https://***@github.com': No such device or address

@ilharp
Copy link

ilharp commented Apr 17, 2021

Thanks. I add .git to my repo.github.url and it works.

@lawrence910426
Copy link

Thanks @oliversturm you saved my day (lol).

Thank you for your solution!!!

@leimao
Copy link

leimao commented Dec 20, 2021

With a different config structure it works correctly now:

deploy:
  type: git
  repo:
    github:
      url: https://github.com/<myusername>/<myrepo>.git
      branch: gh-pages
      token: $GITHUB_TOKEN
  name: <my "visible" name>
  email: <my email>

I'm leaving the issue open - I guess this should either be fixed in code or documented.

At this point I'm only wondering how everybody else does this? I wouldn't normally use this config structure unless I was pushing to multiple repos, which seems like an edge case to me.

Not sure why your solution did not work for me. It kept asking me for username and password.

@leimao
Copy link

leimao commented Dec 20, 2021

I think this should be the correct way of deploying the website using token, although the token unfortunately has to be concretely typed in the yaml file.
hexojs/hexo#2084 (comment)

@mzaydman
Copy link

mzaydman commented Jan 4, 2023

password auth has been deprecated by github, this should really be in the main docs.

@stevenjoezhang
Copy link
Member

password auth has been deprecated by github, this should really be in the main docs.

See also https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-experiencing-github-pushfetch-problems

@isaaxite
Copy link

With a different config structure it works correctly now:

deploy:
  type: git
  repo:
    github:
      url: https://github.com/<myusername>/<myrepo>.git
      branch: gh-pages
      token: $GITHUB_TOKEN
  name: <my "visible" name>
  email: <my email>

I'm leaving the issue open - I guess this should either be fixed in code or documented.

At this point I'm only wondering how everybody else does this? I wouldn't normally use this config structure unless I was pushing to multiple repos, which seems like an edge case to me.

thanks ur share!

@uiolee
Copy link
Member

uiolee commented Sep 6, 2023

same issue

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

No branches or pull requests