Skip to content

Add ability to mint Personal Acess Tokens from CLI #1245

Description

@Zylvian

I'm currently working on a Python app where I quite simply want to check active issues in the private repo that the project is in, but as I want to publish the package. I obviously can't store secrets in the project.
I've used cli in the past, and the interactive authorization flow is amazing. It would be great to have access to it for Github authentication.

Activity

  1. changed the title [-]Publish the cli utils[/-] [+]Add ability to mint Personal Acess Tokens from CLI[/+] on Jun 18, 2020
  2. mislav commented on Jun 18, 2020

    @mislav
    Contributor

    @Zylvian Thanks for the suggestion! Right now this is not supported by our API, but we will keep this open in case something changes on the platform side. #297 (comment)

  3. Zylvian commented on Jun 18, 2020

    @Zylvian
    Author

    Thanks for the response! What an incredible timing to release it haha, just a month short haha

    Well until then, do you have any suggestions how to replicate it? I've scoured the internet for a Github interactive OAuth flow but there is actually none. From what I gathered from your code, I have to open a local socket, open the authorize page in the browser, then listen for the resulting token?
    Also, do you guys save the token env variable GITHUB_TOKEN locally in the virtual environment?

  4. mislav commented on Jun 19, 2020

    @mislav
    Contributor

    Well until then, do you have any suggestions how to replicate it?

    Sure! Register your own OAuth app on github with a http://127.0.0.1/callback callback URL and then you could use our auth/oauth.go implemenation:

    import "github.com/cli/cli/auth"
    
    flow := &auth.OAuthFlow{
    		Hostname:    "github.com",
    		ClientID:     oauthClientID,
    		ClientSecret: oauthClientSecret,
    		Scopes:       []string{"repo"},
    		WriteSuccessHTML: func(w io.Writer) {
    			fmt.Fprintln(w, "yay, you did it!")
    		},
    		VerboseStream: os.Stderr,
    	}
    
    token, err := flow.ObtainAccessToken()

    We are planning to extract this to a package so it's easier to use.

  5. Zylvian commented on Jun 22, 2020

    @Zylvian
    Author

    Thanks for the response!
    So I'm creating my app in Python, any idea how to either implement your method or recreate it?

  6. mislav commented on Jun 22, 2020

    @mislav
    Contributor

    So I'm creating my app in Python, any idea how to either implement your method or recreate it?

    Whoops, now we went from “could GitHub CLI expose so and so feature” to “help me write my Python app” 😆

    For obvious reasons, I can't really advise you on how to implement the OAuth flow in Python. I would suggest using libraries that already do that.

    I will close this now because we have other tickets already open for improving our authorization flow.

  7. Zylvian commented on Jun 25, 2020

    @Zylvian
    Author

    Yeah, apologies for that question, it was more of what strategies to apply when saving the tokens etc., but I was able to deduce that from your code and finished the OAuth process.

    One particular problem I have though, is that I have the same scopes as CLI ("gist repo org:read"), yet I require manual authorization confirmation to access the internal org repo I'm trying to access, whereas CLI doesn't seem to need this whatsoever. Using the access token from your OAuth flow grants me the access I need, yet my access token with exactly the same scopes needs manual approval to work. Any idea why this might be?

    CLI OAuth app:
    https://i.imgur.com/xvsTI6t.png

    My OAuth app:
    https://i.imgur.com/SGk3fP1.png

  8. mislav commented on Jun 25, 2020

    @mislav
    Contributor

    yet I require manual authorization confirmation to access the internal org repo I'm trying to access, whereas CLI doesn't seem to need this whatsoever.

    Yes: the reason is that because our OAuth app is "1st-party" (meaning: owned by GitHub), GitHub treats is as pre-approved. All other OAuth apps need to be approved per-org by admins of those orgs.

  9. Zylvian commented on Jun 25, 2020

    @Zylvian
    Author
  10. Zylvian commented on Jul 2, 2020

    @Zylvian
    Author

    In config_setup, you state that it's safe to embed both the client_id and client_secret in version control. Why is that?

  11. mislav commented on Jul 2, 2020

    @mislav
    Contributor

    @Zylvian The code for any client app (as opposed to a hosted web app) is distributed to its users. Every client app, even if it's just compiled binaries, thus embeds its client_secret that is trivially extracted. So for client apps, we treat their OAuth secret as non-secret.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions