mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 04:35:40 +00:00
44 lines
713 B
Go
44 lines
713 B
Go
package providers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
type GenericUserInfoResponse struct {
|
|
Email string `json:"email"`
|
|
}
|
|
|
|
func GetGenericEmail(client *http.Client, url string) (string, error) {
|
|
res, resErr := client.Get(url)
|
|
|
|
if resErr != nil {
|
|
return "", resErr
|
|
}
|
|
|
|
log.Debug().Msg("Got response from generic provider")
|
|
|
|
body, bodyErr := io.ReadAll(res.Body)
|
|
|
|
if bodyErr != nil {
|
|
return "", bodyErr
|
|
}
|
|
|
|
log.Debug().Msg("Read body from generic provider")
|
|
|
|
var user GenericUserInfoResponse
|
|
|
|
jsonErr := json.Unmarshal(body, &user)
|
|
|
|
if jsonErr != nil {
|
|
return "", jsonErr
|
|
}
|
|
|
|
log.Debug().Msg("Parsed user from generic provider")
|
|
|
|
return user.Email, nil
|
|
}
|