MCPcopy Create free account
hub / github.com/openshift/osin / handleAuthorizationCodeRequest

Method handleAuthorizationCodeRequest

access.go:152–260  ·  view source on GitHub ↗
(w *Response, r *http.Request)

Source from the content-addressed store, hash-verified

150}
151
152func (s *Server) handleAuthorizationCodeRequest(w *Response, r *http.Request) *AccessRequest {
153 // get client authentication
154 auth := s.getClientAuth(w, r, s.Config.AllowClientSecretInParams)
155 if auth == nil {
156 return nil
157 }
158
159 // generate access token
160 ret := &AccessRequest{
161 Type: AUTHORIZATION_CODE,
162 Code: r.FormValue("code"),
163 CodeVerifier: r.FormValue("code_verifier"),
164 RedirectUri: r.FormValue("redirect_uri"),
165 GenerateRefresh: true,
166 Expiration: s.Config.AccessExpiration,
167 HttpRequest: r,
168 }
169
170 // "code" is required
171 if ret.Code == "" {
172 s.setErrorAndLog(w, E_INVALID_GRANT, nil, "auth_code_request=%s", "code is required")
173 return nil
174 }
175
176 // must have a valid client
177 if ret.Client = s.getClient(auth, w.Storage, w); ret.Client == nil {
178 return nil
179 }
180
181 // must be a valid authorization code
182 var err error
183 ret.AuthorizeData, err = w.Storage.LoadAuthorize(ret.Code)
184 if err != nil {
185 s.setErrorAndLog(w, E_INVALID_GRANT, err, "auth_code_request=%s", "error loading authorize data")
186 return nil
187 }
188 if ret.AuthorizeData == nil {
189 s.setErrorAndLog(w, E_UNAUTHORIZED_CLIENT, nil, "auth_code_request=%s", "authorization data is nil")
190 return nil
191 }
192 if ret.AuthorizeData.Client == nil {
193 s.setErrorAndLog(w, E_UNAUTHORIZED_CLIENT, nil, "auth_code_request=%s", "authorization client is nil")
194 return nil
195 }
196 if ret.AuthorizeData.Client.GetRedirectUri() == "" {
197 s.setErrorAndLog(w, E_UNAUTHORIZED_CLIENT, nil, "auth_code_request=%s", "client redirect uri is empty")
198 return nil
199 }
200 if ret.AuthorizeData.IsExpiredAt(s.Now()) {
201 s.setErrorAndLog(w, E_INVALID_GRANT, nil, "auth_code_request=%s", "authorization data is expired")
202 return nil
203 }
204
205 // code must be from the client
206 if ret.AuthorizeData.Client.GetId() != ret.Client.GetId() {
207 s.setErrorAndLog(w, E_INVALID_GRANT, nil, "auth_code_request=%s", "client code does not match")
208 return nil
209 }

Callers 1

HandleAccessRequestMethod · 0.95

Calls 9

getClientAuthMethod · 0.95
setErrorAndLogMethod · 0.95
getClientMethod · 0.95
FirstUriFunction · 0.85
ValidateUriListFunction · 0.85
LoadAuthorizeMethod · 0.65
GetRedirectUriMethod · 0.65
GetIdMethod · 0.65
IsExpiredAtMethod · 0.45

Tested by

no test coverage detected