Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Unified Diff: go/src/infra/libs/auth/internal/user.go

Issue 1153883002: go: infra/libs/* now live in luci-go. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: move the rest too Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/libs/auth/internal/service.go ('k') | go/src/infra/libs/auth/service.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/libs/auth/internal/user.go
diff --git a/go/src/infra/libs/auth/internal/user.go b/go/src/infra/libs/auth/internal/user.go
deleted file mode 100644
index aa84921ef12900ddae78532875b009a761c013bc..0000000000000000000000000000000000000000
--- a/go/src/infra/libs/auth/internal/user.go
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-package internal
-
-import (
- "fmt"
- "time"
-
- "golang.org/x/net/context"
- "golang.org/x/oauth2"
-)
-
-type userAuthTokenProvider struct {
- oauthTokenProvider
-
- ctx context.Context
- config *oauth2.Config
-}
-
-// NewUserAuthTokenProvider returns TokenProvider that can perform 3-legged
-// OAuth flow involving interaction with a user.
-func NewUserAuthTokenProvider(ctx context.Context, clientID, clientSecret string, scopes []string) (TokenProvider, error) {
- return &userAuthTokenProvider{
- oauthTokenProvider: oauthTokenProvider{
- interactive: true,
- tokenFlavor: "user",
- },
- ctx: ctx,
- config: &oauth2.Config{
- ClientID: clientID,
- ClientSecret: clientSecret,
- Endpoint: oauth2.Endpoint{
- AuthURL: "https://accounts.google.com/o/oauth2/auth",
- TokenURL: "https://accounts.google.com/o/oauth2/token",
- },
- RedirectURL: "urn:ietf:wg:oauth:2.0:oob",
- Scopes: scopes,
- },
- }, nil
-}
-
-func (p *userAuthTokenProvider) MintToken() (Token, error) {
- // Grab the authorization code by redirecting a user to a consent screen.
- url := p.config.AuthCodeURL("", oauth2.AccessTypeOffline, oauth2.ApprovalForce)
- fmt.Printf("Visit the URL to get authorization code.\n\n%s\n\n", url)
- fmt.Printf("Authorization code: ")
- var code string
- if _, err := fmt.Scan(&code); err != nil {
- return nil, err
- }
- // Exchange it for a token.
- tok, err := p.config.Exchange(p.ctx, code)
- if err != nil {
- return nil, err
- }
- return makeToken(tok), nil
-}
-
-func (p *userAuthTokenProvider) RefreshToken(tok Token) (Token, error) {
- // Clear expiration time to force token refresh. Do not use 0 since it means
- // that token never expires.
- t := extractOAuthToken(tok)
- t.Expiry = time.Unix(1, 0)
- src := p.config.TokenSource(p.ctx, &t)
- newTok, err := src.Token()
- if err != nil {
- return nil, err
- }
- return makeToken(newTok), nil
-}
« no previous file with comments | « go/src/infra/libs/auth/internal/service.go ('k') | go/src/infra/libs/auth/service.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698