MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / output

Method output

pkg/oauth/server.go:178–240  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, resp *osin.Response)

Source from the content-addressed store, hash-verified

176)
177
178func (s *server) output(w http.ResponseWriter, r *http.Request, resp *osin.Response) {
179 headers := w.Header()
180 for i, k := range resp.Headers {
181 for _, v := range k {
182 headers.Add(i, v)
183 }
184 }
185
186 var osinErr error
187 if resp.IsError {
188 switch resp.ErrorId {
189 case osin.E_INVALID_REQUEST:
190 osinErr = errInvalidRequest
191 case osin.E_UNAUTHORIZED_CLIENT:
192 osinErr = errUnauthorizedClient
193 case osin.E_ACCESS_DENIED:
194 osinErr = errAccessDenied
195 case osin.E_UNSUPPORTED_RESPONSE_TYPE:
196 osinErr = errUnsupportedResponseType
197 case osin.E_INVALID_SCOPE:
198 osinErr = errInvalidScope
199 case osin.E_UNSUPPORTED_GRANT_TYPE:
200 osinErr = errUnsupportedGrantType
201 case osin.E_INVALID_GRANT:
202 osinErr = errInvalidGrant
203 case osin.E_INVALID_CLIENT:
204 osinErr = errInvalidClient
205 default:
206 osinErr = errInternal
207 }
208 if resp.InternalError != nil {
209 if ttnErr, ok := errors.From(resp.InternalError); ok {
210 osinErr = ttnErr
211 } else if _, isURIValidationError := resp.InternalError.(osin.UriValidationError); isURIValidationError {
212 osinErr = errInvalidRedirectURI.WithCause(resp.InternalError)
213 } else {
214 osinErr = osinErr.(*errors.Definition).WithCause(resp.InternalError)
215 }
216 }
217 log.FromContext(r.Context()).WithError(osinErr).Warn("OAuth error")
218 }
219
220 if resp.Type == osin.REDIRECT {
221 location, err := resp.GetRedirectUrl()
222 if err != nil {
223 webhandlers.Error(w, r, err)
224 return
225 }
226 uiMount := strings.TrimSuffix(s.config.UI.MountPath(), "/")
227 if strings.HasPrefix(location, "/code") || strings.HasPrefix(location, "/local-callback") {
228 location = uiMount + location
229 }
230 http.Redirect(w, r, location, http.StatusFound)
231 return
232 }
233
234 if osinErr != nil {
235 webhandlers.Error(w, r, osinErr)

Callers 2

AuthorizeMethod · 0.95
TokenMethod · 0.95

Calls 12

FromFunction · 0.92
FromContextFunction · 0.92
ErrorFunction · 0.92
JSONFunction · 0.92
HeaderMethod · 0.80
MountPathMethod · 0.80
AddMethod · 0.65
WarnMethod · 0.65
WithErrorMethod · 0.65
ContextMethod · 0.65
WithCauseMethod · 0.45
HasPrefixMethod · 0.45

Tested by

no test coverage detected