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

How to include issuer field at OAuth2 token #118

Open
longle2 opened this issue Jul 18, 2019 · 2 comments
Open

How to include issuer field at OAuth2 token #118

longle2 opened this issue Jul 18, 2019 · 2 comments

Comments

@longle2
Copy link

longle2 commented Jul 18, 2019

I'm trying to build an OAuth2 server. My access token (jwt type) server give me doesn't have iss (issuer) field. How can I add it to my token and another fields in payload? This is my server config and token server give me

https://i.stack.imgur.com/yDEy2.png

manager = manage.NewDefaultManager()

    cfg := &manage.Config{
        // access token expiration time
        AccessTokenExp: time.Hour * 2,
        // refresh token expiration time
        RefreshTokenExp: time.Hour * 24 * 3,
        // whether to generate the refreshing token
        IsGenerateRefresh: true,
    }

    manager.SetAuthorizeCodeTokenCfg(cfg)
    manager.SetAuthorizeCodeExp(time.Minute * 30)

    manager.MapAuthorizeGenerate(generates.NewAuthorizeGenerate())
    // generate jwt access token
    manager.MapAccessGenerate(generates.NewJWTAccessGenerate([]byte("12345678"), jwt.SigningMethodHS256))

    manager.MustTokenStorage(store.NewMemoryTokenStore())

    clientStore = store.NewClientStore()
    manager.MapClientStorage(clientStore)

    srv = server.NewDefaultServer(manager)
    srv.SetAllowGetAccessRequest(true)
    // allow the grant types model:AuthorizationCode,PasswordCredentials,ClientCredentials,Refreshing
    srv.SetAllowedGrantType("authorization_code")
    // get client id and secrect, this is default handler
    srv.SetClientInfoHandler(server.ClientFormHandler)
    // way to get user ID
    srv.SetUserAuthorizationHandler(userAuthorizeHandler)
    //
    srv.SetExtensionFieldsHandler(extensionFieldsHanler)
    manager.SetRefreshTokenCfg(manage.DefaultRefreshTokenCfg)

    srv.SetInternalErrorHandler(func(err error) (re *errors.Response) {
        log.Println("Internal Error:", err.Error())
        return
    })

    srv.SetResponseErrorHandler(func(re *errors.Response) {
        log.Println("Response Error:", re.Error.Error())
    })

I tried to find is api docs but I found nothing i tried config here https://go-oauth2.github.io/ but looklike "manager.MapTokenModel(models.NewToken())" doesn't work anymore, I dont know if it can help me

So I need some way to add more filed to my token. Thank for your help

@longle2
Copy link
Author

longle2 commented Jul 18, 2019

I lookup this question and found some answers here https://github.com/go-oauth2/oauth2/issues/98
But i want to ask if there is any option to customize field without change package data. Thank a lot

@xsoroton
Copy link

I have the same problem, I can't spec what I want to use for payload in my tokens

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