chore: simplify
This commit is contained in:
parent
b16c3a5ad1
commit
697f6c40d5
13 changed files with 56 additions and 60 deletions
|
|
@ -91,9 +91,9 @@ func (c *Connection) ExecCmd(function string) (string, error) {
|
|||
}
|
||||
|
||||
parameters := url.Values{
|
||||
"sid": []string{c.SID},
|
||||
"ain": []string{c.AIN},
|
||||
"switchcmd": []string{function},
|
||||
"sid": {c.SID},
|
||||
"ain": {c.AIN},
|
||||
"switchcmd": {function},
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf("%s/webservices/homeautoswitch.lua", c.URI)
|
||||
|
|
@ -156,8 +156,8 @@ func (c *Connection) getSessionID() error {
|
|||
var challresp string
|
||||
if challresp, err = createChallengeResponse(v.Challenge, c.Password); err == nil {
|
||||
params := url.Values{
|
||||
"username": []string{c.User},
|
||||
"response": []string{challresp},
|
||||
"username": {c.User},
|
||||
"response": {challresp},
|
||||
}
|
||||
|
||||
if body, err = c.GetBody(uri + "?" + params.Encode()); err == nil {
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati
|
|||
|
||||
c.statusSnsG = provider.ResettableCached(func() (StatusSNSResponse, error) {
|
||||
parameters := url.Values{
|
||||
"user": []string{c.user},
|
||||
"password": []string{c.password},
|
||||
"cmnd": []string{"Status 8"},
|
||||
"user": {c.user},
|
||||
"password": {c.password},
|
||||
"cmnd": {"Status 8"},
|
||||
}
|
||||
var res StatusSNSResponse
|
||||
err := c.GetJSON(fmt.Sprintf("%s/cm?%s", c.uri, parameters.Encode()), &res)
|
||||
|
|
@ -63,9 +63,9 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati
|
|||
|
||||
c.statusStsG = provider.ResettableCached(func() (StatusSTSResponse, error) {
|
||||
parameters := url.Values{
|
||||
"user": []string{c.user},
|
||||
"password": []string{c.password},
|
||||
"cmnd": []string{"Status 0"},
|
||||
"user": {c.user},
|
||||
"password": {c.password},
|
||||
"cmnd": {"Status 0"},
|
||||
}
|
||||
var res StatusSTSResponse
|
||||
err := c.GetJSON(fmt.Sprintf("%s/cm?%s", c.uri, parameters.Encode()), &res)
|
||||
|
|
@ -120,9 +120,9 @@ func (c *Connection) Enable(enable bool) error {
|
|||
}
|
||||
|
||||
parameters := url.Values{
|
||||
"user": []string{c.user},
|
||||
"password": []string{c.password},
|
||||
"cmnd": []string{cmd},
|
||||
"user": {c.user},
|
||||
"password": {c.password},
|
||||
"cmnd": {cmd},
|
||||
}
|
||||
|
||||
var res PowerResponse
|
||||
|
|
|
|||
|
|
@ -182,10 +182,10 @@ func (v *Identity) brandLogin(cookieClient *request.Helper, user, password strin
|
|||
|
||||
if err == nil {
|
||||
data := url.Values{
|
||||
"username": []string{user},
|
||||
"password": []string{password},
|
||||
"credentialId": []string{""},
|
||||
"rememberMe": []string{"on"},
|
||||
"username": {user},
|
||||
"password": {password},
|
||||
"credentialId": {""},
|
||||
"rememberMe": {"on"},
|
||||
}
|
||||
|
||||
req, err = request.New(http.MethodPost, action, strings.NewReader(data.Encode()), request.URLEncoding)
|
||||
|
|
|
|||
|
|
@ -181,9 +181,9 @@ func (v *Identity) retrieveToken(data url.Values) (*oauth2.Token, error) {
|
|||
|
||||
func (v *Identity) RefreshToken(token *oauth2.Token) (*oauth2.Token, error) {
|
||||
data := url.Values{
|
||||
"redirect_uri": []string{RedirectURI},
|
||||
"refresh_token": []string{token.RefreshToken},
|
||||
"grant_type": []string{"refresh_token"},
|
||||
"redirect_uri": {RedirectURI},
|
||||
"refresh_token": {token.RefreshToken},
|
||||
"grant_type": {"refresh_token"},
|
||||
}
|
||||
|
||||
return v.retrieveToken(data)
|
||||
|
|
|
|||
|
|
@ -105,8 +105,8 @@ func (v *Identity) RefreshToken(token *oauth2.Token) (*oauth2.Token, error) {
|
|||
defer v.mu.Unlock()
|
||||
|
||||
data := url.Values{
|
||||
"grant_type": []string{"refresh_token"},
|
||||
"refresh_token": []string{token.RefreshToken},
|
||||
"grant_type": {"refresh_token"},
|
||||
"refresh_token": {token.RefreshToken},
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf("%s/as/token.oauth2", IdUri)
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@ func (vs *SetupAPI) RequestPin() (bool, *string, error) {
|
|||
|
||||
func (vs *SetupAPI) RequestAccessToken(nonce string, pin string) (*oauth2.Token, error) {
|
||||
data := url.Values{
|
||||
"client_id": []string{ClientId},
|
||||
"grant_type": []string{"password"},
|
||||
"password": []string{fmt.Sprintf("%s:%s", nonce, pin)},
|
||||
"scope": []string{"openid email phone profile offline_access ciam-uid"},
|
||||
"username": []string{vs.account},
|
||||
"client_id": {ClientId},
|
||||
"grant_type": {"password"},
|
||||
"password": {fmt.Sprintf("%s:%s", nonce, pin)},
|
||||
"scope": {"openid email phone profile offline_access ciam-uid"},
|
||||
"username": {vs.account},
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf("%s/as/token.oauth2", IdUri)
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@ func (v *Niu) login() error {
|
|||
md5hash := hex.EncodeToString(hash.Sum(nil))
|
||||
|
||||
data := url.Values{
|
||||
"account": []string{v.user},
|
||||
"password": []string{md5hash},
|
||||
"grant_type": []string{"password"},
|
||||
"scope": []string{"base"},
|
||||
"app_id": []string{"niu_8xt1afu6"},
|
||||
"account": {v.user},
|
||||
"password": {md5hash},
|
||||
"grant_type": {"password"},
|
||||
"scope": {"base"},
|
||||
"app_id": {"niu_8xt1afu6"},
|
||||
}
|
||||
|
||||
uri := niu.AuthURI + "/v3/api/oauth2/token"
|
||||
|
|
|
|||
|
|
@ -95,9 +95,9 @@ func (v *Identity) login() (*oauth2.Token, error) {
|
|||
// Submit credentials directly to the login endpoint
|
||||
loginURL := fmt.Sprintf("%s/as/%s/resume/as/authorization.ping", OAuthURI, resumePath)
|
||||
data := url.Values{
|
||||
"pf.username": []string{v.user},
|
||||
"pf.pass": []string{v.password},
|
||||
"client_id": []string{ClientID},
|
||||
"pf.username": {v.user},
|
||||
"pf.pass": {v.password},
|
||||
"client_id": {ClientID},
|
||||
}
|
||||
|
||||
req, _ = request.New(http.MethodPost, loginURL, strings.NewReader(data.Encode()), map[string]string{
|
||||
|
|
@ -120,11 +120,11 @@ func (v *Identity) login() (*oauth2.Token, error) {
|
|||
|
||||
// Exchange code for token
|
||||
data = url.Values{
|
||||
"grant_type": []string{"authorization_code"},
|
||||
"code": []string{code},
|
||||
"code_verifier": []string{cv},
|
||||
"client_id": []string{ClientID},
|
||||
"redirect_uri": []string{RedirectURI},
|
||||
"grant_type": {"authorization_code"},
|
||||
"code": {code},
|
||||
"code_verifier": {cv},
|
||||
"client_id": {ClientID},
|
||||
"redirect_uri": {RedirectURI},
|
||||
}
|
||||
|
||||
var token oauth2.Token
|
||||
|
|
|
|||
|
|
@ -46,9 +46,7 @@ func NewAPI(log *util.Logger, identity oauth2.TokenSource, realm, id string) *AP
|
|||
}
|
||||
|
||||
func (v *API) clientID() string {
|
||||
return url.Values{
|
||||
"client_id": []string{v.id},
|
||||
}.Encode()
|
||||
return url.Values{"client_id": {v.id}}.Encode()
|
||||
}
|
||||
|
||||
// Vehicles implements the /vehicles response
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ func (v *Identity) Login(user, password string) error {
|
|||
|
||||
func (v *Identity) sessionCookie(user, password string) (string, error) {
|
||||
data := url.Values{
|
||||
"loginID": []string{user},
|
||||
"password": []string{password},
|
||||
"apiKey": []string{v.gigya.APIKey},
|
||||
"loginID": {user},
|
||||
"password": {password},
|
||||
"apiKey": {v.gigya.APIKey},
|
||||
}
|
||||
|
||||
var res gigyaResponse
|
||||
|
|
@ -76,8 +76,8 @@ func (v *Identity) sessionCookie(user, password string) (string, error) {
|
|||
|
||||
func (v *Identity) personID(sessionCookie string) (string, error) {
|
||||
data := url.Values{
|
||||
"apiKey": []string{v.gigya.APIKey},
|
||||
"login_token": []string{sessionCookie},
|
||||
"apiKey": {v.gigya.APIKey},
|
||||
"login_token": {sessionCookie},
|
||||
}
|
||||
|
||||
var res gigyaResponse
|
||||
|
|
@ -89,10 +89,10 @@ func (v *Identity) personID(sessionCookie string) (string, error) {
|
|||
|
||||
func (v *Identity) jwtToken(sessionCookie string) (string, error) {
|
||||
data := url.Values{
|
||||
"apiKey": []string{v.gigya.APIKey},
|
||||
"login_token": []string{sessionCookie},
|
||||
"fields": []string{"data.personId,data.gigyaDataCenter"},
|
||||
"expiration": []string{"900"},
|
||||
"apiKey": {v.gigya.APIKey},
|
||||
"login_token": {sessionCookie},
|
||||
"fields": {"data.personId,data.gigyaDataCenter"},
|
||||
"expiration": {"900"},
|
||||
}
|
||||
|
||||
var res gigyaResponse
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ func (v *Identity) retrieveToken(data url.Values) (*oauth2.Token, error) {
|
|||
|
||||
func (v *Identity) RefreshToken(token *oauth2.Token) (*oauth2.Token, error) {
|
||||
data := url.Values{
|
||||
"refresh_token": []string{token.RefreshToken},
|
||||
"grant_type": []string{"refresh_token"},
|
||||
"refresh_token": {token.RefreshToken},
|
||||
"grant_type": {"refresh_token"},
|
||||
}
|
||||
|
||||
token, err := v.retrieveToken(data)
|
||||
|
|
|
|||
|
|
@ -103,9 +103,7 @@ func mbbUserId(log *util.Logger, ts oauth2.TokenSource, uid string) (string, err
|
|||
Base: client.Transport,
|
||||
}
|
||||
|
||||
data := url.Values{
|
||||
"scopeId": []string{"commonMandatoryFields"},
|
||||
}
|
||||
data := url.Values{"scopeId": {"commonMandatoryFields"}}
|
||||
|
||||
var mandatoryConsentInfo struct {
|
||||
MbbUserId string `json:"mbbUserId"`
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ func (v *Service) Login(uri, user, password string) (url.Values, error) {
|
|||
|
||||
// add nonce and state
|
||||
query := url.Values{
|
||||
"nonce": []string{lo.RandomString(43, lo.LettersCharset)},
|
||||
"state": []string{uuid.NewString()},
|
||||
"nonce": {lo.RandomString(43, lo.LettersCharset)},
|
||||
"state": {uuid.NewString()},
|
||||
}
|
||||
|
||||
var vars FormVars
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue