2016-01-25 23:42:05 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-08-11 22:31:16 +00:00
|
|
|
"context"
|
2016-01-25 23:42:05 +00:00
|
|
|
"encoding/json"
|
|
|
|
"flag"
|
2016-03-04 21:53:06 +00:00
|
|
|
"math/rand"
|
2016-01-25 23:42:05 +00:00
|
|
|
"net/http"
|
2016-03-04 21:53:06 +00:00
|
|
|
"strconv"
|
2016-01-25 23:42:05 +00:00
|
|
|
"strings"
|
2016-03-04 21:53:06 +00:00
|
|
|
"time"
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext "github.com/docker/distribution/context"
|
2016-01-25 23:42:05 +00:00
|
|
|
"github.com/docker/distribution/registry/api/errcode"
|
|
|
|
"github.com/docker/distribution/registry/auth"
|
|
|
|
_ "github.com/docker/distribution/registry/auth/htpasswd"
|
|
|
|
"github.com/docker/libtrust"
|
|
|
|
"github.com/gorilla/mux"
|
2017-06-23 19:45:04 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-01-25 23:42:05 +00:00
|
|
|
)
|
|
|
|
|
2016-11-15 17:19:33 +00:00
|
|
|
var (
|
|
|
|
enforceRepoClass bool
|
|
|
|
)
|
|
|
|
|
2016-01-25 23:42:05 +00:00
|
|
|
func main() {
|
|
|
|
var (
|
|
|
|
issuer = &TokenIssuer{}
|
|
|
|
pkFile string
|
|
|
|
addr string
|
|
|
|
debug bool
|
|
|
|
err error
|
|
|
|
|
|
|
|
passwdFile string
|
|
|
|
realm string
|
|
|
|
|
|
|
|
cert string
|
|
|
|
certKey string
|
|
|
|
)
|
|
|
|
|
|
|
|
flag.StringVar(&issuer.Issuer, "issuer", "distribution-token-server", "Issuer string for token")
|
|
|
|
flag.StringVar(&pkFile, "key", "", "Private key file")
|
|
|
|
flag.StringVar(&addr, "addr", "localhost:8080", "Address to listen on")
|
|
|
|
flag.BoolVar(&debug, "debug", false, "Debug mode")
|
|
|
|
|
|
|
|
flag.StringVar(&passwdFile, "passwd", ".htpasswd", "Passwd file")
|
|
|
|
flag.StringVar(&realm, "realm", "", "Authentication realm")
|
|
|
|
|
|
|
|
flag.StringVar(&cert, "tlscert", "", "Certificate file for TLS")
|
|
|
|
flag.StringVar(&certKey, "tlskey", "", "Certificate key for TLS")
|
|
|
|
|
2016-11-15 17:19:33 +00:00
|
|
|
flag.BoolVar(&enforceRepoClass, "enforce-class", false, "Enforce policy for single repository class")
|
|
|
|
|
2016-01-25 23:42:05 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if debug {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
if pkFile == "" {
|
|
|
|
issuer.SigningKey, err = libtrust.GenerateECP256PrivateKey()
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("Error generating private key: %v", err)
|
|
|
|
}
|
|
|
|
logrus.Debugf("Using newly generated key with id %s", issuer.SigningKey.KeyID())
|
|
|
|
} else {
|
|
|
|
issuer.SigningKey, err = libtrust.LoadKeyFile(pkFile)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("Error loading key file %s: %v", pkFile, err)
|
|
|
|
}
|
|
|
|
logrus.Debugf("Loaded private key with id %s", issuer.SigningKey.KeyID())
|
|
|
|
}
|
|
|
|
|
|
|
|
if realm == "" {
|
|
|
|
logrus.Fatalf("Must provide realm")
|
|
|
|
}
|
|
|
|
|
|
|
|
ac, err := auth.GetAccessController("htpasswd", map[string]interface{}{
|
|
|
|
"realm": realm,
|
|
|
|
"path": passwdFile,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("Error initializing access controller: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-03-04 21:53:06 +00:00
|
|
|
// TODO: Make configurable
|
|
|
|
issuer.Expiration = 15 * time.Minute
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx := dcontext.Background()
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
ts := &tokenServer{
|
|
|
|
issuer: issuer,
|
|
|
|
accessController: ac,
|
2016-03-04 21:53:06 +00:00
|
|
|
refreshCache: map[string]refreshToken{},
|
2016-01-25 23:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
router := mux.NewRouter()
|
|
|
|
router.Path("/token/").Methods("GET").Handler(handlerWithContext(ctx, ts.getToken))
|
2016-03-04 21:53:06 +00:00
|
|
|
router.Path("/token/").Methods("POST").Handler(handlerWithContext(ctx, ts.postToken))
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
if cert == "" {
|
|
|
|
err = http.ListenAndServe(addr, router)
|
|
|
|
} else if certKey == "" {
|
2016-01-28 23:47:22 +00:00
|
|
|
logrus.Fatalf("Must provide certficate (-tlscert) and key (-tlskey)")
|
2016-01-25 23:42:05 +00:00
|
|
|
} else {
|
|
|
|
err = http.ListenAndServeTLS(addr, cert, certKey, router)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logrus.Infof("Error serving: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// handlerWithContext wraps the given context-aware handler by setting up the
|
|
|
|
// request context from a base context.
|
|
|
|
func handlerWithContext(ctx context.Context, handler func(context.Context, http.ResponseWriter, *http.Request)) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx := dcontext.WithRequest(ctx, r)
|
|
|
|
logger := dcontext.GetRequestLogger(ctx)
|
|
|
|
ctx = dcontext.WithLogger(ctx, logger)
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
handler(ctx, w, r)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func handleError(ctx context.Context, err error, w http.ResponseWriter) {
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx, w = dcontext.WithResponseWriter(ctx, w)
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
if serveErr := errcode.ServeJSON(w, err); serveErr != nil {
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetResponseLogger(ctx).Errorf("error sending error response: %v", serveErr)
|
2016-01-25 23:42:05 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetResponseLogger(ctx).Info("application error")
|
2016-01-25 23:42:05 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 21:53:06 +00:00
|
|
|
var refreshCharacters = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
|
|
|
|
|
|
|
const refreshTokenLength = 15
|
|
|
|
|
|
|
|
func newRefreshToken() string {
|
|
|
|
s := make([]rune, refreshTokenLength)
|
|
|
|
for i := range s {
|
|
|
|
s[i] = refreshCharacters[rand.Intn(len(refreshCharacters))]
|
|
|
|
}
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
type refreshToken struct {
|
|
|
|
subject string
|
|
|
|
service string
|
|
|
|
}
|
|
|
|
|
2016-01-25 23:42:05 +00:00
|
|
|
type tokenServer struct {
|
|
|
|
issuer *TokenIssuer
|
|
|
|
accessController auth.AccessController
|
2016-03-04 21:53:06 +00:00
|
|
|
refreshCache map[string]refreshToken
|
|
|
|
}
|
|
|
|
|
|
|
|
type tokenResponse struct {
|
|
|
|
Token string `json:"access_token"`
|
|
|
|
RefreshToken string `json:"refresh_token,omitempty"`
|
|
|
|
ExpiresIn int `json:"expires_in,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-11-15 17:19:33 +00:00
|
|
|
var repositoryClassCache = map[string]string{}
|
|
|
|
|
2016-03-04 21:53:06 +00:00
|
|
|
func filterAccessList(ctx context.Context, scope string, requestedAccessList []auth.Access) []auth.Access {
|
|
|
|
if !strings.HasSuffix(scope, "/") {
|
|
|
|
scope = scope + "/"
|
|
|
|
}
|
|
|
|
grantedAccessList := make([]auth.Access, 0, len(requestedAccessList))
|
|
|
|
for _, access := range requestedAccessList {
|
2016-07-13 00:13:43 +00:00
|
|
|
if access.Type == "repository" {
|
|
|
|
if !strings.HasPrefix(access.Name, scope) {
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Debugf("Resource scope not allowed: %s", access.Name)
|
2016-07-13 00:13:43 +00:00
|
|
|
continue
|
|
|
|
}
|
2016-11-15 17:19:33 +00:00
|
|
|
if enforceRepoClass {
|
|
|
|
if class, ok := repositoryClassCache[access.Name]; ok {
|
|
|
|
if class != access.Class {
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Debugf("Different repository class: %q, previously %q", access.Class, class)
|
2016-11-15 17:19:33 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else if strings.EqualFold(access.Action, "push") {
|
|
|
|
repositoryClassCache[access.Name] = access.Class
|
|
|
|
}
|
|
|
|
}
|
2016-07-13 00:13:43 +00:00
|
|
|
} else if access.Type == "registry" {
|
|
|
|
if access.Name != "catalog" {
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Debugf("Unknown registry resource: %s", access.Name)
|
2016-07-13 00:13:43 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
// TODO: Limit some actions to "admin" users
|
|
|
|
} else {
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Debugf("Skipping unsupported resource type: %s", access.Type)
|
2016-03-04 21:53:06 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
grantedAccessList = append(grantedAccessList, access)
|
|
|
|
}
|
|
|
|
return grantedAccessList
|
2016-01-25 23:42:05 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 00:47:12 +00:00
|
|
|
type acctSubject struct{}
|
|
|
|
|
|
|
|
func (acctSubject) String() string { return "acctSubject" }
|
|
|
|
|
|
|
|
type requestedAccess struct{}
|
|
|
|
|
|
|
|
func (requestedAccess) String() string { return "requestedAccess" }
|
|
|
|
|
|
|
|
type grantedAccess struct{}
|
|
|
|
|
|
|
|
func (grantedAccess) String() string { return "grantedAccess" }
|
|
|
|
|
2016-01-25 23:42:05 +00:00
|
|
|
// getToken handles authenticating the request and authorizing access to the
|
|
|
|
// requested scopes.
|
|
|
|
func (ts *tokenServer) getToken(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Info("getToken")
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
params := r.URL.Query()
|
|
|
|
service := params.Get("service")
|
|
|
|
scopeSpecifiers := params["scope"]
|
2016-03-04 21:53:06 +00:00
|
|
|
var offline bool
|
|
|
|
if offlineStr := params.Get("offline_token"); offlineStr != "" {
|
|
|
|
var err error
|
|
|
|
offline, err = strconv.ParseBool(offlineStr)
|
|
|
|
if err != nil {
|
|
|
|
handleError(ctx, ErrorBadTokenOption.WithDetail(err), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2016-01-28 23:47:22 +00:00
|
|
|
requestedAccessList := ResolveScopeSpecifiers(ctx, scopeSpecifiers)
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
authorizedCtx, err := ts.accessController.Authorized(ctx, requestedAccessList...)
|
|
|
|
if err != nil {
|
|
|
|
challenge, ok := err.(auth.Challenge)
|
|
|
|
if !ok {
|
|
|
|
handleError(ctx, err, w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get response context.
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx, w = dcontext.WithResponseWriter(ctx, w)
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
challenge.SetHeaders(w)
|
|
|
|
handleError(ctx, errcode.ErrorCodeUnauthorized.WithDetail(challenge.Error()), w)
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetResponseLogger(ctx).Info("get token authentication challenge")
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx = authorizedCtx
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
username := dcontext.GetStringValue(ctx, "auth.user.name")
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2016-10-06 00:47:12 +00:00
|
|
|
ctx = context.WithValue(ctx, acctSubject{}, username)
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx, acctSubject{}))
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Info("authenticated client")
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2016-10-06 00:47:12 +00:00
|
|
|
ctx = context.WithValue(ctx, requestedAccess{}, requestedAccessList)
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx, requestedAccess{}))
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2016-03-04 21:53:06 +00:00
|
|
|
grantedAccessList := filterAccessList(ctx, username, requestedAccessList)
|
2016-10-06 00:47:12 +00:00
|
|
|
ctx = context.WithValue(ctx, grantedAccess{}, grantedAccessList)
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx, grantedAccess{}))
|
2016-03-04 21:53:06 +00:00
|
|
|
|
|
|
|
token, err := ts.issuer.CreateJWT(username, service, grantedAccessList)
|
|
|
|
if err != nil {
|
|
|
|
handleError(ctx, err, w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Info("authorized client")
|
2016-03-04 21:53:06 +00:00
|
|
|
|
|
|
|
response := tokenResponse{
|
|
|
|
Token: token,
|
|
|
|
ExpiresIn: int(ts.issuer.Expiration.Seconds()),
|
|
|
|
}
|
|
|
|
|
|
|
|
if offline {
|
|
|
|
response.RefreshToken = newRefreshToken()
|
|
|
|
ts.refreshCache[response.RefreshToken] = refreshToken{
|
|
|
|
subject: username,
|
|
|
|
service: service,
|
2016-01-25 23:42:05 +00:00
|
|
|
}
|
2016-03-04 21:53:06 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx, w = dcontext.WithResponseWriter(ctx, w)
|
2016-03-04 21:53:06 +00:00
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
json.NewEncoder(w).Encode(response)
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetResponseLogger(ctx).Info("get token complete")
|
2016-03-04 21:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type postTokenResponse struct {
|
|
|
|
Token string `json:"access_token"`
|
|
|
|
Scope string `json:"scope,omitempty"`
|
|
|
|
ExpiresIn int `json:"expires_in,omitempty"`
|
|
|
|
IssuedAt string `json:"issued_at,omitempty"`
|
|
|
|
RefreshToken string `json:"refresh_token,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// postToken handles authenticating the request and authorizing access to the
|
|
|
|
// requested scopes.
|
|
|
|
func (ts *tokenServer) postToken(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
|
|
|
grantType := r.PostFormValue("grant_type")
|
|
|
|
if grantType == "" {
|
|
|
|
handleError(ctx, ErrorMissingRequiredField.WithDetail("missing grant_type value"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
service := r.PostFormValue("service")
|
|
|
|
if service == "" {
|
|
|
|
handleError(ctx, ErrorMissingRequiredField.WithDetail("missing service value"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
clientID := r.PostFormValue("client_id")
|
|
|
|
if clientID == "" {
|
|
|
|
handleError(ctx, ErrorMissingRequiredField.WithDetail("missing client_id value"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var offline bool
|
|
|
|
switch r.PostFormValue("access_type") {
|
|
|
|
case "", "online":
|
|
|
|
case "offline":
|
|
|
|
offline = true
|
|
|
|
default:
|
|
|
|
handleError(ctx, ErrorUnsupportedValue.WithDetail("unknown access_type value"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
requestedAccessList := ResolveScopeList(ctx, r.PostFormValue("scope"))
|
|
|
|
|
|
|
|
var subject string
|
|
|
|
var rToken string
|
|
|
|
switch grantType {
|
|
|
|
case "refresh_token":
|
|
|
|
rToken = r.PostFormValue("refresh_token")
|
|
|
|
if rToken == "" {
|
|
|
|
handleError(ctx, ErrorUnsupportedValue.WithDetail("missing refresh_token value"), w)
|
|
|
|
return
|
2016-01-25 23:42:05 +00:00
|
|
|
}
|
2016-03-04 21:53:06 +00:00
|
|
|
rt, ok := ts.refreshCache[rToken]
|
|
|
|
if !ok || rt.service != service {
|
|
|
|
handleError(ctx, errcode.ErrorCodeUnauthorized.WithDetail("invalid refresh token"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
subject = rt.subject
|
|
|
|
case "password":
|
|
|
|
ca, ok := ts.accessController.(auth.CredentialAuthenticator)
|
|
|
|
if !ok {
|
|
|
|
handleError(ctx, ErrorUnsupportedValue.WithDetail("password grant type not supported"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
subject = r.PostFormValue("username")
|
|
|
|
if subject == "" {
|
|
|
|
handleError(ctx, ErrorUnsupportedValue.WithDetail("missing username value"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
password := r.PostFormValue("password")
|
|
|
|
if password == "" {
|
|
|
|
handleError(ctx, ErrorUnsupportedValue.WithDetail("missing password value"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := ca.AuthenticateUser(subject, password); err != nil {
|
|
|
|
handleError(ctx, errcode.ErrorCodeUnauthorized.WithDetail("invalid credentials"), w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
handleError(ctx, ErrorUnsupportedValue.WithDetail("unknown grant_type value"), w)
|
|
|
|
return
|
2016-01-25 23:42:05 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 00:47:12 +00:00
|
|
|
ctx = context.WithValue(ctx, acctSubject{}, subject)
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx, acctSubject{}))
|
2016-03-04 21:53:06 +00:00
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Info("authenticated client")
|
2016-03-04 21:53:06 +00:00
|
|
|
|
2016-10-06 00:47:12 +00:00
|
|
|
ctx = context.WithValue(ctx, requestedAccess{}, requestedAccessList)
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx, requestedAccess{}))
|
2016-03-04 21:53:06 +00:00
|
|
|
|
|
|
|
grantedAccessList := filterAccessList(ctx, subject, requestedAccessList)
|
2016-10-06 00:47:12 +00:00
|
|
|
ctx = context.WithValue(ctx, grantedAccess{}, grantedAccessList)
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx, grantedAccess{}))
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2016-03-04 21:53:06 +00:00
|
|
|
token, err := ts.issuer.CreateJWT(subject, service, grantedAccessList)
|
2016-01-25 23:42:05 +00:00
|
|
|
if err != nil {
|
|
|
|
handleError(ctx, err, w)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetLogger(ctx).Info("authorized client")
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2016-03-04 21:53:06 +00:00
|
|
|
response := postTokenResponse{
|
|
|
|
Token: token,
|
|
|
|
ExpiresIn: int(ts.issuer.Expiration.Seconds()),
|
|
|
|
IssuedAt: time.Now().UTC().Format(time.RFC3339),
|
|
|
|
Scope: ToScopeList(grantedAccessList),
|
|
|
|
}
|
|
|
|
|
|
|
|
if offline {
|
|
|
|
rToken = newRefreshToken()
|
|
|
|
ts.refreshCache[rToken] = refreshToken{
|
|
|
|
subject: subject,
|
|
|
|
service: service,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if rToken != "" {
|
|
|
|
response.RefreshToken = rToken
|
|
|
|
}
|
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
ctx, w = dcontext.WithResponseWriter(ctx, w)
|
2016-01-25 23:42:05 +00:00
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
2016-03-04 21:53:06 +00:00
|
|
|
json.NewEncoder(w).Encode(response)
|
2016-01-25 23:42:05 +00:00
|
|
|
|
2017-08-11 22:31:16 +00:00
|
|
|
dcontext.GetResponseLogger(ctx).Info("post token complete")
|
2016-01-25 23:42:05 +00:00
|
|
|
}
|