@@ -75,7 +75,11 @@ func extractTokenParams(r *http.Request, callbackURL *url.URL) (tokenParams, []c
75
75
return params , nil , nil
76
76
}
77
77
78
- func Tokens (db database.Store , defaultLifetime time.Duration ) http.HandlerFunc {
78
+ // Tokens
79
+ // TODO: the sessions lifetime config passed is for coder api tokens.
80
+ // Should er have a separate config for oauth2 tokens? They are related,
81
+ // but they are not the same.
82
+ func Tokens (db database.Store , lifetimes codersdk.SessionLifetime ) http.HandlerFunc {
79
83
return func (rw http.ResponseWriter , r * http.Request ) {
80
84
ctx := r .Context ()
81
85
app := httpmw .OAuth2ProviderApp (r )
@@ -104,9 +108,9 @@ func Tokens(db database.Store, defaultLifetime time.Duration) http.HandlerFunc {
104
108
switch params .grantType {
105
109
// TODO: Client creds, device code.
106
110
case codersdk .OAuth2ProviderGrantTypeRefreshToken :
107
- token , err = refreshTokenGrant (ctx , db , app , defaultLifetime , params )
111
+ token , err = refreshTokenGrant (ctx , db , app , lifetimes , params )
108
112
case codersdk .OAuth2ProviderGrantTypeAuthorizationCode :
109
- token , err = authorizationCodeGrant (ctx , db , app , defaultLifetime , params )
113
+ token , err = authorizationCodeGrant (ctx , db , app , lifetimes , params )
110
114
default :
111
115
// Grant types are validated by the parser, so getting through here means
112
116
// the developer added a type but forgot to add a case here.
@@ -137,7 +141,7 @@ func Tokens(db database.Store, defaultLifetime time.Duration) http.HandlerFunc {
137
141
}
138
142
}
139
143
140
- func authorizationCodeGrant (ctx context.Context , db database.Store , app database.OAuth2ProviderApp , defaultLifetime time. Duration , params tokenParams ) (oauth2.Token , error ) {
144
+ func authorizationCodeGrant (ctx context.Context , db database.Store , app database.OAuth2ProviderApp , lifetimes codersdk. SessionLifetime , params tokenParams ) (oauth2.Token , error ) {
141
145
// Validate the client secret.
142
146
secret , err := parseSecret (params .clientSecret )
143
147
if err != nil {
@@ -195,11 +199,9 @@ func authorizationCodeGrant(ctx context.Context, db database.Store, app database
195
199
// TODO: We are ignoring scopes for now.
196
200
tokenName := fmt .Sprintf ("%s_%s_oauth_session_token" , dbCode .UserID , app .ID )
197
201
key , sessionToken , err := apikey .Generate (apikey.CreateParams {
198
- UserID : dbCode .UserID ,
199
- LoginType : database .LoginTypeOAuth2ProviderApp ,
200
- // TODO: This is just the lifetime for api keys, maybe have its own config
201
- // settings. #11693
202
- DefaultLifetime : defaultLifetime ,
202
+ UserID : dbCode .UserID ,
203
+ LoginType : database .LoginTypeOAuth2ProviderApp ,
204
+ SessionCfg : lifetimes ,
203
205
// For now, we allow only one token per app and user at a time.
204
206
TokenName : tokenName ,
205
207
})
@@ -271,7 +273,7 @@ func authorizationCodeGrant(ctx context.Context, db database.Store, app database
271
273
}, nil
272
274
}
273
275
274
- func refreshTokenGrant (ctx context.Context , db database.Store , app database.OAuth2ProviderApp , defaultLifetime time. Duration , params tokenParams ) (oauth2.Token , error ) {
276
+ func refreshTokenGrant (ctx context.Context , db database.Store , app database.OAuth2ProviderApp , lifetimes codersdk. SessionLifetime , params tokenParams ) (oauth2.Token , error ) {
275
277
// Validate the token.
276
278
token , err := parseSecret (params .refreshToken )
277
279
if err != nil {
@@ -326,11 +328,9 @@ func refreshTokenGrant(ctx context.Context, db database.Store, app database.OAut
326
328
// TODO: We are ignoring scopes for now.
327
329
tokenName := fmt .Sprintf ("%s_%s_oauth_session_token" , prevKey .UserID , app .ID )
328
330
key , sessionToken , err := apikey .Generate (apikey.CreateParams {
329
- UserID : prevKey .UserID ,
330
- LoginType : database .LoginTypeOAuth2ProviderApp ,
331
- // TODO: This is just the lifetime for api keys, maybe have its own config
332
- // settings. #11693
333
- DefaultLifetime : defaultLifetime ,
331
+ UserID : prevKey .UserID ,
332
+ LoginType : database .LoginTypeOAuth2ProviderApp ,
333
+ SessionCfg : lifetimes ,
334
334
// For now, we allow only one token per app and user at a time.
335
335
TokenName : tokenName ,
336
336
})
0 commit comments