토큰을 사용하여 GitHub로 인증
개인 액세스 토큰을 사용하여 GitHub로 인증하려고합니다. github의 도움말 파일에는 cURL 메서드를 사용하여 인증 ( https://help.github.com/articles/creating-an-access-token-for-command-line-use ) 을 사용하도록 명시되어 있습니다 . 시도했지만 여전히 GitHub로 푸시 할 수 없습니다. 인증되지 않은 서버 (Travis-CI)에서 푸시를 시도하고 있습니다.
cd $HOME
git config --global user.email "emailaddress@yahoo.com"
git config --global user.name "username"
curl -u "username:<MYTOKEN>" https://github.com/username/ol3-1.git
git clone --branch=gh-pages https://github.com/username/ol3-1.git gh-pages
cd gh-pages
mkdir buildtest
cd buildtest
touch asdf.asdf
git add -f .
git commit -m "Travis build $TRAVIS_BUILD_NUMBER pushed to gh-pages"
git push -fq origin gh-pages
이 코드는 오류를 발생시킵니다.
remote : scuzzlebuzzle / ol3-1.git에 대한 익명 액세스가 거부되었습니다.
치명적 : ' https://github.com/scuzzlebuzzle/ol3-1.git/ ' "에 대한 인증 실패
당신의 curl
명령은 완전히 잘못되었습니다. 다음을 사용해야합니다.
curl -H 'Authorization: token <MYTOKEN>' ...
그 외에도 실제로 개인 경우 저장소를 복제하도록 컴퓨터를 인증하지 않습니다. (그러나 살펴보면 그렇지 않음을 나타냅니다.) 일반적으로 수행하는 작업은 다음과 같습니다.
git clone https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git --branch=gh-pages gh-pages
그러면 저장소를 복제 할 때 생성 된 원격에 자격 증명이 추가됩니다. 그러나 안타깝게도 Travis가 저장소를 복제하는 방법을 제어 할 수 없으므로 원격으로 편집해야합니다.
# After cloning
cd gh-pages
git remote rm origin
git remote add origin https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git
그러면 자격 증명이 내장 된 원격을 사용하도록 프로젝트가 수정됩니다.
먼저 개인 액세스 토큰 (PAT)을 생성해야합니다. 여기에 설명되어 있습니다 : https://help.github.com/articles/creating-an-access-token-for-command-line-use/
웃기게도이 기사는 그것을 만드는 방법을 알려주지 만 어떻게해야할지 전혀 모른다. 약 한 시간의 트롤링 문서와 Stack Overflow 후에 마침내 답을 찾았습니다.
$ git clone https://github.com/user-or-organisation/myrepo.git
Username: <my-username>
Password: <my-personal-access-token>
원격으로 작업하면서 로컬 변경이있는 동안 회사 정책에 따라 2 단계 인증 을 활성화해야 했기 때문에 실제로는 clone
필요 하지 않았습니다 push
. 리모컨을 삭제하고 다시 만들어야하는 많은 곳에서 읽었지만 실제로 내 일반 push
명령은 clone
위와 똑같이 작동했으며 리모컨은 변경되지 않았습니다.
$ git push https://github.com/user-or-organisation/myrepo.git
Username: <my-username>
Password: <my-personal-access-token>
(@YMHuang은 문서 링크를 통해 저를 올바른 길로 안내했습니다.)
"성 열쇠"를 넘겨주지 않으려면 ...
sigmavirus24의 응답은 Travis에게 상당히 광범위한 권한이있는 토큰을 제공하도록 요구합니다. GitHub는 "내 공개 저장소 모두 작성"또는 "내 개인 저장소 모두 쓰기"와 같은 넓은 범위의 토큰 만 제공하기 때문입니다.
좀 더 많은 작업을 통해 액세스를 강화하려는 경우 Travis 암호화 yaml 필드와 결합 된 GitHub 배포 키를 사용할 수 있습니다.
기술이 어떻게 작동하는지에 대한 스케치 는 다음과 같습니다 .
먼저라는 RSA 배포 키를 생성하고 (를 통해 ssh-keygen
) my_key
github 저장소 설정에서 배포 키로 추가합니다.
그때...
$ password=`openssl rand -hex 32`
$ cat my_key | openssl aes-256-cbc -k "$password" -a > my_key.enc
$ travis encrypt --add password=$password -r my-github-user/my-repo
그런 다음 $password
yaml 파일에 추가하여 통합시 파일을 사용 하여 배포 키를 해독합니다.
before_script:
- openssl aes-256-cbc -k "$password" -d -a -in my_key.enc -out my_deploy_key
- echo -e "Host github.com\n IdentityFile /path/to/my_deploy_key" > ~/.ssh/config
- echo "github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" > ~/.ssh/known_hosts
참고 : 마지막 줄에는 github의 RSA 키가 미리 채워져 있으므로 연결시 수동으로 수락 할 필요가 없습니다.
OAuth 토큰을 사용한 자동화 / Git 자동화
$ git clone https://github.com/username/repo.git
Username: your_token
Password:
git push
명령 에서도 작동합니다 .
참조 : https://help.github.com/articles/git-automation-with-oauth-tokens/
This worked for me using ssh:
Settings → Developer settings → Generate new token.
git remote rm origin
git remote add origin https://[APPLICATION]:[NEW TOKEN]@github.com/[ORGANISATION]/[REPO].git
By having struggling so many hours on applying GitHub token finally it works as below:
$ cf_export GITHUB_TOKEN=$(codefresh get context github --decrypt -o yaml | yq -y .spec.data.auth.password)
- code follows Codefresh guidance on cloning a repo using token (freestyle}
- test carried: sed
%d%H%M
on match word'-123456-whatever'
- push back to the repo (which is private repo)
- triggered by DockerHub webhooks
Following is the complete code:
version: '1.0'
steps:
get_git_token:
title: Reading Github token
image: codefresh/cli
commands:
- cf_export GITHUB_TOKEN=$(codefresh get context github --decrypt -o yaml | yq -y .spec.data.auth.password)
main_clone:
title: Updating the repo
image: alpine/git:latest
commands:
- git clone https://chetabahana:$GITHUB_TOKEN@github.com/chetabahana/compose.git
- cd compose && git remote rm origin
- git config --global user.name "chetabahana"
- git config --global user.email "chetabahana@gmail.com"
- git remote add origin https://chetabahana:$GITHUB_TOKEN@github.com/chetabahana/compose.git
- sed -i "s/-[0-9]\{1,\}-\([a-zA-Z0-9_]*\)'/-`date +%d%H%M`-whatever'/g" cloudbuild.yaml
- git status && git add . && git commit -m "fresh commit" && git push -u origin master
Output...
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: cloudbuild.yaml
no changes added to commit (use "git add" and/or "git commit -a")
[master dbab20f] fresh commit
1 file changed, 1 insertion(+), 1 deletion(-)
Enumerating objects: 5, done.
Counting objects: 20% (1/5) ... Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 33% (1/3) ... Writing objects: 100% (3/3), 283 bytes | 283.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 0% (0/2) ... (2/2), completed with 2 local objects.
To https://github.com/chetabahana/compose.git
bbb6d2f..dbab20f master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reading environment variable exporting file contents.
Successfully ran freestyle step: Cloning the repo
참고URL : https://stackoverflow.com/questions/18935539/authenticate-with-github-using-a-token
'development' 카테고리의 다른 글
ASP MVC 3의 한보기에 두 모델 (0) | 2020.09.02 |
---|---|
Insert 명령을 실행하고 Sql에 삽입 된 Id 반환 (0) | 2020.09.02 |
목록을 다시 정렬하려면 어떻게해야합니까? (0) | 2020.09.02 |
링크를 버튼처럼 보이게 (0) | 2020.09.02 |
EventHandler에 매개 변수 전달 (0) | 2020.09.02 |