~netlandish/gobwebs-oauth2

c7b753bbeaf5561f49fe7a809f7d3cab8b032098 — Peter Sanchez 1 year, 6 months ago a312023
Displaying scope access in metadata
1 files changed, 19 insertions(+), 1 deletions(-)

M routes.go
M routes.go => routes.go +19 -1
@@ 674,6 674,24 @@ func (s *Service) OAuthMetadata(c echo.Context) error {
		return err
	}

	var scopes []string
	for _, scope := range s.config.Scopes {
		parts := strings.Split(scope, ":")
		if len(parts) > 1 {
			access := parts[1]
			if access != "RO" && access != "RW" {
				parts = parts[:1] // Invalid access, reset
				scope = parts[0]
			} else {
				scopes = append(scopes, fmt.Sprintf("%s:%s", parts[0], parts[1]))
			}
		}
		if len(parts) == 1 {
			scopes = append(scopes, fmt.Sprintf("%s:RO", scope))
			scopes = append(scopes, fmt.Sprintf("%s:RW", scope))
		}
	}

	ret := struct {
		Issuer        string   `json:"issuer"`
		AuthEndpoint  string   `json:"authorization_endpoint"`


@@ 688,7 706,7 @@ func (s *Service) OAuthMetadata(c echo.Context) error {
		Issuer:        origin,
		AuthEndpoint:  aURL,
		TokenEndpoint: tURL,
		Scopes:        s.config.Scopes,
		Scopes:        scopes,
		Responses:     []string{"code"},
		Grants:        []string{"authorization_code"},
		Doc:           s.config.DocumentationURL,