ipn: add Login backend command for sign-in with token

The StartLoginInteractive command is for delegating the sign-in flow
to a browser. The Android Gooogle Sign-In SDK inverts the flow by
giving the client ID tokens.

Add a new backend command for accepting such tokens by exposing the existing
controlclient.Client.Login support for OAuth2 tokens. Introduce a custom
TokenType to distinguish ID tokens from other OAuth2 tokens.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-07-13 22:13:11 +02:00
parent 969206fe88
commit 6e8f0860af
6 changed files with 48 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import (
"time"
"github.com/tailscale/wireguard-go/wgcfg"
"golang.org/x/oauth2"
"inet.af/netaddr"
"tailscale.com/control/controlclient"
"tailscale.com/ipn/ipnstate"
@@ -612,6 +613,16 @@ func (b *LocalBackend) getEngineStatus() EngineStatus {
return b.engineStatus
}
// Login implements Backend.
func (b *LocalBackend) Login(token *oauth2.Token) {
b.mu.Lock()
b.assertClientLocked()
c := b.c
b.mu.Unlock()
c.Login(token, controlclient.LoginInteractive)
}
// StartLoginInteractive implements Backend. It requests a new
// interactive login from controlclient, unless such a flow is already
// in progress, in which case StartLoginInteractive attempts to pick