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

[FEAT] Pick up token from gh auth login CLI #1854

Merged
merged 2 commits into from
Sep 11, 2023

Conversation

nfx
Copy link
Contributor

@nfx nfx commented Aug 22, 2023

This PR adds the use of token persisted by GitHub CLI (https://cli.github.com) via running the gh auth token --hostname $base_url command and using the token from that command.

Resolves #1822


Before the change?

gh-authenticated machines had to pass the token via env variable:

  • gh auth login
  • GITHUB_TOKEN=$(gh auth token) terraform apply

After the change?

gh-authenticated machines do not have to pass the token via env variable:

  • gh auth login
  • terraform apply

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

This PR adds the use of token persisted by GitHub CLI (https://cli.github.com) via running the `gh auth token --hostname $base_url` command and using the token from that command.
@nfx
Copy link
Contributor Author

nfx commented Aug 23, 2023

cc @kfcampbell @nickfloyd this one is without introducing any new module dependencies.

@nickfloyd nickfloyd added Awaiting response Type: Feature New feature or request labels Aug 25, 2023
@nfx nfx requested a review from kfcampbell August 26, 2023 18:35
@nfx
Copy link
Contributor Author

nfx commented Aug 26, 2023

@kfcampbell docs updated

@nfx
Copy link
Contributor Author

nfx commented Aug 30, 2023

@kfcampbell Following up

2 similar comments
@nfx
Copy link
Contributor Author

nfx commented Sep 1, 2023

@kfcampbell Following up

@nfx
Copy link
Contributor Author

nfx commented Sep 7, 2023

@kfcampbell Following up

@nfx
Copy link
Contributor Author

nfx commented Sep 10, 2023

@kfcampbell @nickfloyd when can we get this released? 😀

@ajschmidt8
Copy link

My team is also eager to see this PR merged.

thank you for your work, @nfx.

@nickfloyd
Copy link
Contributor

I'll be taking a look at this today, if everything checks out, I'll get it merged and released as well. Thanks for the patience and contributions here! ❤️

@nickfloyd nickfloyd changed the title Pick up token from gh auth login CLI [FEAT] Pick up token from gh auth login CLI Sep 11, 2023
Copy link
Contributor

@nickfloyd nickfloyd left a comment

Choose a reason for hiding this comment

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

Thank you for the contributions! ❤️

@nickfloyd nickfloyd merged commit a6becdc into integrations:main Sep 11, 2023
3 checks passed
@nfx nfx deleted the gh-cli-auth branch September 15, 2023 10:11
nfx added a commit to nfx/terraform-provider-github that referenced this pull request Sep 15, 2023
This PR is a follow-up to integrations#1854

GitHub CLI uses different base URLs in `~/.config/gh/hosts.yml`, so when we're using the standard base path of this provider, it doesn't align with how `gh` CLI stores the credentials. The following doesn't work:

```
$ gh auth token --hostname api.github.com
> no oauth token
```
... but the following does work correctly

```
$ gh auth token --hostname github.com
> gh..<valid token>
```

attempted a workaround with

```
provider "github" {
  owner = "..."
  base_url = "github.com"
}
```

But it didn't work as expected.
avidspartan1 pushed a commit to avidspartan1/terraform-provider-github that referenced this pull request Feb 5, 2024
This PR is a follow-up to integrations#1854

GitHub CLI uses different base URLs in `~/.config/gh/hosts.yml`, so when we're using the standard base path of this provider, it doesn't align with how `gh` CLI stores the credentials. The following doesn't work:

```
$ gh auth token --hostname api.github.com
> no oauth token
```
... but the following does work correctly

```
$ gh auth token --hostname github.com
> gh..<valid token>
```

attempted a workaround with

```
provider "github" {
  owner = "..."
  base_url = "github.com"
}
```

But it didn't work as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT]: Authentication via gh cli (go-gh)
4 participants