|
|
@ -544,15 +544,30 @@ func GrantApplicationOAuth(ctx *context.Context) { |
|
|
|
ctx.ServerError("GetOAuth2ApplicationByClientID", err) |
|
|
|
ctx.ServerError("GetOAuth2ApplicationByClientID", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
grant, err := app.CreateGrant(ctx, ctx.Doer.ID, form.Scope) |
|
|
|
grant, err := app.GetGrantByUserID(ctx, ctx.Doer.ID) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
handleServerError(ctx, form.State, form.RedirectURI) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if grant == nil { |
|
|
|
|
|
|
|
grant, err = app.CreateGrant(ctx, ctx.Doer.ID, form.Scope) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
handleAuthorizeError(ctx, AuthorizeError{ |
|
|
|
|
|
|
|
State: form.State, |
|
|
|
|
|
|
|
ErrorDescription: "cannot create grant for user", |
|
|
|
|
|
|
|
ErrorCode: ErrorCodeServerError, |
|
|
|
|
|
|
|
}, form.RedirectURI) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if grant.Scope != form.Scope { |
|
|
|
handleAuthorizeError(ctx, AuthorizeError{ |
|
|
|
handleAuthorizeError(ctx, AuthorizeError{ |
|
|
|
State: form.State, |
|
|
|
State: form.State, |
|
|
|
ErrorDescription: "cannot create grant for user", |
|
|
|
ErrorDescription: "a grant exists with different scope", |
|
|
|
ErrorCode: ErrorCodeServerError, |
|
|
|
ErrorCode: ErrorCodeServerError, |
|
|
|
}, form.RedirectURI) |
|
|
|
}, form.RedirectURI) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(form.Nonce) > 0 { |
|
|
|
if len(form.Nonce) > 0 { |
|
|
|
err := grant.SetNonce(ctx, form.Nonce) |
|
|
|
err := grant.SetNonce(ctx, form.Nonce) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|