hexo-deployer-git icon indicating copy to clipboard operation
hexo-deployer-git copied to clipboard

Token deploy prompts for username

Open oliversturm opened this issue 5 years ago • 16 comments

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 avatar Jan 08 '20 16:01 oliversturm

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?

oliversturm avatar Jan 08 '20 17:01 oliversturm

@oliversturm

export GITHUB_TOKEN=<token>

Will it work?

SukkaW avatar Jan 08 '20 18:01 SukkaW

@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 avatar Jan 08 '20 19:01 oliversturm

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 avatar Jan 08 '20 19:01 oliversturm

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.

oliversturm avatar Jan 08 '20 19:01 oliversturm

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

PinkyJie avatar Jan 15 '20 12:01 PinkyJie

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

tienhm0202 avatar Apr 07 '20 01:04 tienhm0202

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

carlos-algms avatar Jan 20 '21 13:01 carlos-algms

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

ilharp avatar Apr 17 '21 16:04 ilharp

Thanks @oliversturm you saved my day (lol).

Thank you for your solution!!!

lawrence910426 avatar Aug 25 '21 15:08 lawrence910426

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 avatar Dec 20 '21 05:12 leimao

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. https://github.com/hexojs/hexo/issues/2084#issuecomment-466350089

leimao avatar Dec 20 '21 05:12 leimao

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

mzaydman avatar Jan 04 '23 22:01 mzaydman

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

stevenjoezhang avatar Jan 14 '23 18:01 stevenjoezhang

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!

isaaxite avatar Feb 28 '23 13:02 isaaxite

same issue

uiolee avatar Sep 06 '23 08:09 uiolee