-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oauthdevice: Rename to
auth
; simplify interface
This change simplifies the `oauthdevice.Authenticator` interface from the two-step `FetchCode` + `FetchToken` to a combined single method `Authenticate` that essentially chains the two code paths. The former interface may over-fit the device code auth flow, whereas the new interface may allow for non-device-code-flows to be implemented in the future. Since this change causes the interface to no longer be device-code-specific, the former package name no longer makes sense. This change results in the following renames: `package oauthdevice` -> `package auth` `oauthdevice.Authenticator` -> `auth.Backend` `oauthdevice.Auth` -> `auth.DeviceCode` `oauthdevice.NewAuth` -> `auth.NewDeviceCode` This change moves the browser-opening step from `main` into `auth.DeviceCode` as a consequence (which more accurately reflects the reality that not all auth flows involve opening a browser). Tests for main are simpler but tests for `auth.DeviceCode` are more complex as a result. Tests for `auth.DeviceCode` mock the underlying transport to perform validation on the HTTP requests and responses, bringing some of the `oauth2` package logic into the test. This results in slight over-testing, but may allow us to more easily validate `engflow_auth` against actual HTTP responses from our oauth endpoint in the future.
- Loading branch information
1 parent
3751600
commit 10d8b09
Showing
9 changed files
with
322 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
load("@rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "auth", | ||
srcs = ["authenticator.go"], | ||
importpath = "github.com/EngFlow/auth/internal/auth", | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//internal/autherr", | ||
"//internal/browser", | ||
"@org_golang_x_oauth2//:oauth2", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "auth_test", | ||
srcs = ["authenticator_test.go"], | ||
embed = [":auth"], | ||
deps = [ | ||
"//internal/browser", | ||
"@com_github_stretchr_testify//assert", | ||
"@com_github_stretchr_testify//mock", | ||
"@org_golang_x_oauth2//:oauth2", | ||
], | ||
) |
Oops, something went wrong.