From d636210b860b287686c7b297eb2dfd7eae3f65ff Mon Sep 17 00:00:00 2001 From: Flonja <20887403+Flonja@users.noreply.github.com> Date: Sat, 30 Jul 2022 00:01:22 +0200 Subject: [PATCH] auth/live.go: Add RefreshTokenSourceWriter --- minecraft/auth/live.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/minecraft/auth/live.go b/minecraft/auth/live.go index a1e36438..edd54bde 100644 --- a/minecraft/auth/live.go +++ b/minecraft/auth/live.go @@ -51,7 +51,15 @@ func (src *tokenSource) Token() (*oauth2.Token, error) { // refreshes the token everytime it expires. Note that this function must be used over oauth2.ReuseTokenSource // due to that function not refreshing with the correct scopes. func RefreshTokenSource(t *oauth2.Token) oauth2.TokenSource { - return oauth2.ReuseTokenSource(t, &tokenSource{w: os.Stdout, t: t}) + return RefreshTokenSourceWriter(t, os.Stdout) +} + +// RefreshTokenSourceWriter returns a new oauth2.TokenSource using the oauth2.Token passed that automatically +// refreshes the token everytime it expires. It requests from io.Writer if the oauth2.Token is invalid. +// Note that this function must be used over oauth2.ReuseTokenSource due to that +// function not refreshing with the correct scopes. +func RefreshTokenSourceWriter(t *oauth2.Token, w io.Writer) oauth2.TokenSource { + return oauth2.ReuseTokenSource(t, &tokenSource{w: w, t: t}) } // RequestLiveToken does a login request for Microsoft Live Connect using device auth. A login URL will be