actions / create-github-app-token

GitHub Action for creating a GitHub App Installation Access Token
https://github.com/marketplace/actions/create-github-app-token
MIT License
321 stars 46 forks source link

Add built-in support for basic auth #144

Closed danra closed 1 month ago

danra commented 1 month ago

This allows using the encoded token for basic auth-based git access.

This is useful for scripts expecting to be able to access private git repos. My specific case was using CPM.cmake in a repo that brings in other private repos as dependencies.

While the encoding to make this work is very simple, the documentation for it is sparse and it is not trivial to figure out, so there's value in providing this out of the box.

danra commented 1 month ago

I would suggest to add a step which pipes the string x-access-token:${{ steps.app-token.outputs.token }} | bash64

Unfortunately, that's not cross-platform (doesn't work on Windows). I used github-script for cross-platform base64 encoding:

- name: Prepare basic auth credentials
  id: basic-auth-creds
  uses: actions/github-script@v7
  with:
    script: return btoa("x-access-token:${{ steps.app-token.outputs.token }}")
    result-encoding: string

- name: Checkout with private submodules
  env:
    GIT_CONFIG_COUNT: 1
    GIT_CONFIG_KEY_0: http.https://github.com/.extraheader
    GIT_CONFIG_VALUE_0: "AUTHORIZATION: basic ${{ steps.basic-auth-creds.outputs.result }}"
  # Access allowed to private submodules in the current owner's installation
  run: git clone --recurse-submodules --shallow-submodules https://github.com/${{ github.repository }}

In future, can you please create an issue first before a pull request? We appreciate the effort you put into it, but having a discussion first might help prevent unnecessary work and frustration.

Sure, no worries. I'll close the PR. A README addition would be helpful, indeed.