cli / oauth

A library for performing OAuth Device flow and Web application flow in Go client apps.
https://pkg.go.dev/github.com/cli/oauth
MIT License
460 stars 63 forks source link

Support more auth endpoints #3

Closed v-braun closed 5 months ago

v-braun commented 3 years ago

Hi,

this is a draft to support other endpoints than GitHub.

In my specific case, I had to use Microsofts Auth Endpoint wich is a bit different than that from GitHub. See details here.

I needed the support of additional post parameters in the AccessToken function and also to handle JSON based responses.

My solution is not that generic (to support others) as I wanted, because I had to focus on my specific case but maybe it is a good starting point for other auth endpoints.

v-braun commented 3 years ago

@mislav I see already that there are some tests failing (not only linter tests).

I am working on a GO based desktop app based on wails. Within the app I am authenticating against office365 wich has some differences to GitHub within the open ID protocol details.

1.: I have to specify additional query parameters within the browser URL browser.OpenURL wich are:

"response_type": "code",
"response_mode": "query"

see details here

2.: flow.AccessToken need in my case some additional parameters that has to been posted, this are:

"grant_type":  "authorization_code",
"redirect_uri": "redirect url",

see details here

3.: api.PostForm handle payload that is provided via a JSON content type. O365 response is a JSON. For that I analyze the contentype ad parse a dictionary based on this. FormResponse.Get has a check and returns the accesstoken (and refreshtoken) based on the previouse received ContentType (see here).

Please see this as a working draft, we can also close the PR til I have refactored the code and fixed the Tests. I am right now busy on my project but hopefully can contribute here again till end of this week.

williammartin commented 5 months ago

This seems incredibly stale so I'm going to go ahead and close this to get it off our books 🙏