Merge branch 'T705-oauth' into oauth-wrapper
This commit is contained in:
commit
ad5f72d8a4
1 changed files with 10 additions and 0 deletions
10
oauth.go
10
oauth.go
|
@ -26,6 +26,7 @@ type TokenResponse struct {
|
||||||
ExpiresIn int `json:"expires_in"`
|
ExpiresIn int `json:"expires_in"`
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken string `json:"refresh_token"`
|
||||||
TokenType string `json:"token_type"`
|
TokenType string `json:"token_type"`
|
||||||
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InspectResponse contains data returned when an access token is inspected.
|
// InspectResponse contains data returned when an access token is inspected.
|
||||||
|
@ -113,11 +114,13 @@ func (h oauthHandler) viewOauthCallback(app *App, w http.ResponseWriter, r *http
|
||||||
|
|
||||||
err := h.DB.ValidateOAuthState(ctx, state)
|
err := h.DB.ValidateOAuthState(ctx, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("Unable to ValidateOAuthState: %s", err)
|
||||||
return impart.HTTPError{http.StatusInternalServerError, err.Error()}
|
return impart.HTTPError{http.StatusInternalServerError, err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenResponse, err := h.exchangeOauthCode(ctx, code)
|
tokenResponse, err := h.exchangeOauthCode(ctx, code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("Unable to exchangeOauthCode: %s", err)
|
||||||
return impart.HTTPError{http.StatusInternalServerError, err.Error()}
|
return impart.HTTPError{http.StatusInternalServerError, err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,11 +128,13 @@ func (h oauthHandler) viewOauthCallback(app *App, w http.ResponseWriter, r *http
|
||||||
// it really really works.
|
// it really really works.
|
||||||
tokenInfo, err := h.inspectOauthAccessToken(ctx, tokenResponse.AccessToken)
|
tokenInfo, err := h.inspectOauthAccessToken(ctx, tokenResponse.AccessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("Unable to inspectOauthAccessToken: %s", err)
|
||||||
return impart.HTTPError{http.StatusInternalServerError, err.Error()}
|
return impart.HTTPError{http.StatusInternalServerError, err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
localUserID, err := h.DB.GetIDForRemoteUser(ctx, tokenInfo.UserID)
|
localUserID, err := h.DB.GetIDForRemoteUser(ctx, tokenInfo.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Error("Unable to GetIDForRemoteUser: %s", err)
|
||||||
return impart.HTTPError{http.StatusInternalServerError, err.Error()}
|
return impart.HTTPError{http.StatusInternalServerError, err.Error()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,6 +218,11 @@ func (h oauthHandler) exchangeOauthCode(ctx context.Context, code string) (*Toke
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the response for an error message, and return it if there is one.
|
||||||
|
if tokenResponse.Error != "" {
|
||||||
|
return nil, fmt.Errorf(tokenResponse.Error)
|
||||||
|
}
|
||||||
return &tokenResponse, nil
|
return &tokenResponse, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue