Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why must set UserAuthorizationHandler? #259

Open
xiaofengzs opened this issue Dec 7, 2023 · 1 comment
Open

Why must set UserAuthorizationHandler? #259

xiaofengzs opened this issue Dec 7, 2023 · 1 comment

Comments

@xiaofengzs
Copy link

When i set up my demo according the doc. i met access denied. When i debug it, i found i must set UserAuthorizationHandler.
My question is, when i sent authorization request to get code in oauth2 authorization code flow like the following code, there is no user info in url. So why must set UserAuthorizationHandler? What is userId for here?

http://localhost:9096/authorize?client_id=000000&response_type=code

image
@wd0517
Copy link

wd0517 commented Dec 15, 2023

oauth2/server/handler.go

Lines 22 to 23 in b369a2d

// UserAuthorizationHandler get user id from request authorization
UserAuthorizationHandler func(w http.ResponseWriter, r *http.Request) (userID string, err error)

For authorization code flow, it need to know which user is granting permission to third-party application, since the user is already logged in at this point, you need to implement the UserAuthorizationHandler to retrieve and return the authenticated user.

To run the broken demo in the readme, you can add some dummy code as below:

    ....
    srv.SetClientInfoHandler(server.ClientFormHandler)
    srv.SetUserAuthorizationHandler(func(w http.ResponseWriter, r *http.Request) (userID string, err error) {
        return "1", nil
    })
    .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants