mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-10 13:58:46 +00:00
remove unusable signup feature
This commit is contained in:
parent
1c3cb0f358
commit
6b3240dd9a
4 changed files with 0 additions and 169 deletions
|
@ -92,50 +92,3 @@ func RegisterApp(ctx context.Context, appConfig *AppConfig) (*Application, error
|
|||
|
||||
return &app, nil
|
||||
}
|
||||
|
||||
type AppAuth struct {
|
||||
http.Client
|
||||
}
|
||||
|
||||
// RegisterApp make auth application and return app token.
|
||||
func AuthApp(ctx context.Context, appConfig *Application, instance string) (*string, error) {
|
||||
var appAuth AppAuth
|
||||
params := url.Values{}
|
||||
params.Set("client_id", appConfig.ClientID)
|
||||
params.Set("client_secret", appConfig.ClientSecret)
|
||||
params.Set("redirect_uris", "urn:ietf:wg:oauth:2.0:oob")
|
||||
params.Set("grant_type", "client_credentials")
|
||||
params.Set("scope", "read write follow")
|
||||
|
||||
u, err := url.Parse("https://" + instance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u.Path = path.Join(u.Path, "/oauth/token")
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(params.Encode()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
resp, err := appAuth.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, parseAPIError("bad request", resp)
|
||||
}
|
||||
|
||||
var res struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
||||
err = json.NewDecoder(resp.Body).Decode(&res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &res.AccessToken, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue