func (server UbuntuSSOServer) GetTokenWithOTP(email, password, otp, tokenName string) (*SSOData, error) {
	credentials := map[string]string{
		"email":      email,
		"password":   password,
		"token_name": tokenName,
	}
	if otp != "" {
		credentials["otp"] = otp
	}
	jsonCredentials, err := json.Marshal(credentials)
	if err != nil {
		return nil, err
	}
	response, err := http.Post(
		server.tokenURL(),
		"application/json",
		strings.NewReader(string(jsonCredentials)))
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()
	if response.StatusCode != 200 && response.StatusCode != 201 {
		return nil, getError(response)
	}
	ssodata := SSOData{}
	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return nil, err
	}
	err = json.Unmarshal(body, &ssodata)
	if err != nil {
		return nil, err
	}
	ssodata.Realm = "API"
	return &ssodata, nil
}
// GetTokenWithOTP retrieves an oauth token from the Ubuntu SSO server.
// Using the user credentials including two-factor authentication and the
// token name, an oauth token is retrieved that can later be used to sign
// requests. If an error is returned from the identity server then it
// will be of type *Error. If otp is blank then this is identical to
// GetToken.
GetTokenWithOTP retrieves an oauth token from the Ubuntu SSO server.
Using the user credentials including two-factor authentication and the
token name, an oauth token is retrieved that can later be used to sign
requests. If an error is returned from the identity server then it
will be of type *Error. If otp is blank then this is identical to
GetToken.
// GetTokenWithOTP retrieves an oauth token from the Ubuntu SSO server . // Using the user credentials including two - factor authentication and the // token name an oauth token is retrieved that can later be used to sign // requests . If an error is returned from the identity server then it // will be of type * Error . If otp is blank then this is identical to // GetToken .
func (server UbuntuSSOServer) GetTokenWithOTP(email, password, otp, tokenName string) (*SSOData, error) {
	credentials := map[string]string{
		"email":      email,
		"password":   password,
		"token_name": tokenName,
	}
	if otp != "" {
		credentials["otp"] = otp
	}
	jsonCredentials, err := json.Marshal(credentials)
	if err != nil {
		return nil, err
	}
	response, err := http.Post(
		server.tokenURL(),
		"application/json",
		strings.NewReader(string(jsonCredentials)))
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()
	if response.StatusCode != 200 && response.StatusCode != 201 {
		return nil, getError(response)
	}
	ssodata := SSOData{}
	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return nil, err
	}
	err = json.Unmarshal(body, &ssodata)
	if err != nil {
		return nil, err
	}
	ssodata.Realm = "API"
	return &ssodata, nil
}
func ( server UbuntuSSOServer ) GetTokenWithOTP ( email , password , otp , tokenName string ) ( * SSOData , error ) { credentials := map [ string ] string { " " : email , " " : password , " " : tokenName , } if otp != " " { credentials [ " " ] = otp } jsonCredentials , err := json . Marshal ( credentials ) if err != nil { return nil , err } response , err := http . Post ( server . tokenURL ( ) , " " , strings . NewReader ( string ( jsonCredentials ) ) ) if err != nil { return nil , err } defer response . Body . Close ( ) if response . StatusCode != 200 && response . StatusCode != 201 { return nil , getError ( response ) } ssodata := SSOData { } body , err := ioutil . ReadAll ( response . Body ) if err != nil { return nil , err } err = json . Unmarshal ( body , & ssodata ) if err != nil { return nil , err } ssodata . Realm = " " return & ssodata , nil }
GetTokenWithOTP retrieves an oauth token from the Ubuntu SSO server.
GetTokenWithOTP retrieves an oauth token from the Ubuntu SSO server .