Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CF Push: Ensure we refresh token #4254

Merged
merged 2 commits into from
May 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/jetstream/plugins/cfapppush/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,22 +479,30 @@ func (cfAppPush *CFAppPush) getConfigData(echoContext echo.Context, cnsiGUID str
sendErrorMessage(clientWebSocket, err, CLOSE_NO_SESSION)
return nil, err
}
cnsiTokenRecord, found := cfAppPush.portalProxy.GetCNSITokenRecord(cnsiGUID, userID)
_, found := cfAppPush.portalProxy.GetCNSITokenRecord(cnsiGUID, userID)
if !found {
log.Warnf("Failed to retrieve record for CNSI %s", cnsiGUID)
sendErrorMessage(clientWebSocket, err, CLOSE_NO_CNSI_USERTOKEN)
return nil, errors.New("Failed to find token record")
}

// Refresh token first - makes sure it will be valid when we do the push
refreshedTokenRec, err := cfAppPush.portalProxy.RefreshOAuthToken(cnsiRecord.SkipSSLValidation, cnsiRecord.GUID, userID, cnsiRecord.ClientId, cnsiRecord.ClientSecret, cnsiRecord.TokenEndpoint)
if err != nil {
log.Warnf("Couldn't get refresh token for endpoint with GUID %s", cnsiRecord.GUID)
sendErrorMessage(clientWebSocket, err, CLOSE_NO_CNSI_USERTOKEN)
return nil, fmt.Errorf("Couldn't get refresh token for endpoint with GUID %s", cnsiRecord.GUID)
}

config := &CFPushAppConfig{
AuthorizationEndpoint: cnsiRecord.AuthorizationEndpoint,
CFClient: cnsiRecord.ClientId,
CFClientSecret: cnsiRecord.ClientSecret,
APIEndpointURL: cnsiRecord.APIEndpoint.String(),
DopplerLoggingEndpoint: cnsiRecord.DopplerLoggingEndpoint,
SkipSSLValidation: cnsiRecord.SkipSSLValidation,
AuthToken: cnsiTokenRecord.AuthToken,
RefreshToken: cnsiTokenRecord.RefreshToken,
AuthToken: refreshedTokenRec.AuthToken,
RefreshToken: refreshedTokenRec.RefreshToken,
OrgGUID: orgGUID,
OrgName: orgName,
SpaceGUID: spaceGUID,
Expand Down