lib/app/auth.go

28 lines
840 B
Go
Raw Permalink Normal View History

2021-01-19 01:50:45 +00:00
package app
import (
"code.tnxs.net/taxnexus/lib/api/auth/auth_client"
"code.tnxs.net/taxnexus/lib/api/auth/auth_client/user"
"code.tnxs.net/taxnexus/lib/api/auth/auth_models"
)
var authClient = auth_client.Default
// CheckAPIUser is exported
func CheckAPIUser(token *string) (*User, error) {
sugar.Debug("app.CheckAPIUser: 📥")
params := user.NewGetUsersParams()
params.Apikey = token
response, err := authClient.User.GetUsers(params, apiUsers["auth"].Auth)
if err != nil {
sugar.Warnf("app.CheckAPIUser: ❗ Access attempt with invalid API key: %s", *token)
return nil, err
}
var obj *auth_models.User
for _, itm := range response.Payload.Data { // single iteration execution
obj = itm
}
sugar.Debugf("app.CheckAPIUser: 📤 👍 ID = %s, Name = %s", obj.ID, obj.Name)
return MarshalAuthUserToSwagger(obj), nil
}