github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/auth.go (about)

     1  package v7action
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/actor/actionerror"
     7  	"code.cloudfoundry.org/cli/api/uaa/constant"
     8  )
     9  
    10  func (actor Actor) Authenticate(credentials map[string]string, origin string, grantType constant.GrantType) error {
    11  	if grantType == constant.GrantTypePassword && actor.Config.UAAGrantType() == string(constant.GrantTypeClientCredentials) {
    12  		return actionerror.PasswordGrantTypeLogoutRequiredError{}
    13  	}
    14  
    15  	actor.Config.UnsetOrganizationAndSpaceInformation()
    16  	accessToken, refreshToken, err := actor.UAAClient.Authenticate(credentials, origin, grantType)
    17  	if err != nil {
    18  		actor.Config.SetTokenInformation("", "", "")
    19  		return err
    20  	}
    21  
    22  	accessToken = fmt.Sprintf("bearer %s", accessToken)
    23  	actor.Config.SetTokenInformation(accessToken, refreshToken, "")
    24  
    25  	if grantType == constant.GrantTypePassword {
    26  		actor.Config.SetUAAGrantType("")
    27  	} else {
    28  		actor.Config.SetUAAGrantType(string(grantType))
    29  	}
    30  
    31  	if grantType == constant.GrantTypeClientCredentials {
    32  		actor.Config.SetUAAClientCredentials(credentials["client_id"], "")
    33  	}
    34  
    35  	return nil
    36  }