Files
probo/pkg/iam/oauth2/request_context.go
Ludovic Vielle 3ebb221a9b Add OAuth2 API scope registration and enforcement
Register v1 API scopes in coredata, advertise them in OIDC discovery
and protected-resource metadata, show them on the consent screen, and
enforce scope-to-action mapping in the IAM Authorizer before policy
evaluation.

Signed-off-by: Ludovic Vielle <ludovic@probo.com>
2026-06-18 19:07:25 +02:00

49 lines
1.7 KiB
Go

// Copyright (c) 2026 Probo Inc <hello@probo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package oauth2
import (
"context"
"go.probo.inc/probo/pkg/coredata"
)
type contextKey struct{ name string }
var (
accessTokenContextKey = &contextKey{name: "oauth2_access_token"}
clientContextKey = &contextKey{name: "oauth2_client"}
)
func ContextWithAccessToken(ctx context.Context, accessToken *coredata.OAuth2AccessToken) context.Context {
return context.WithValue(ctx, accessTokenContextKey, accessToken)
}
func AccessTokenFromContext(ctx context.Context) (*coredata.OAuth2AccessToken, bool) {
accessToken, ok := ctx.Value(accessTokenContextKey).(*coredata.OAuth2AccessToken)
return accessToken, ok
}
func ContextWithClient(ctx context.Context, client *coredata.OAuth2Client) context.Context {
return context.WithValue(ctx, clientContextKey, client)
}
func ClientFromContext(ctx context.Context) (*coredata.OAuth2Client, bool) {
client, ok := ctx.Value(clientContextKey).(*coredata.OAuth2Client)
return client, ok
}