Skip to content

Commit c621910

Browse files
authored
Merge pull request #43 from overmindtech/new-scopes
Request minimal scopes on interactive authentication
2 parents 68c3443 + 8fc4741 commit c621910

File tree

11 files changed

+88
-16
lines changed

11 files changed

+88
-16
lines changed

cmd/createbookmark.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func CreateBookmark(signals chan os.Signal, ready chan bool) int {
6666
))
6767
defer span.End()
6868

69-
ctx, err = ensureToken(ctx, signals)
69+
ctx, err = ensureToken(ctx, []string{"changes:write"}, signals)
7070
if err != nil {
7171
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
7272
"url": viper.GetString("url"),

cmd/datamaps/awssource.go

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/endchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func EndChange(signals chan os.Signal, ready chan bool) int {
5252
))
5353
defer span.End()
5454

55-
ctx, err = ensureToken(ctx, signals)
55+
ctx, err = ensureToken(ctx, []string{"changes:write"}, signals)
5656
if err != nil {
5757
log.WithContext(ctx).WithFields(log.Fields{
5858
"url": viper.GetString("url"),

cmd/getaffectedbookmarks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func GetAffectedBookmarks(signals chan os.Signal, ready chan bool) int {
7070
))
7171
defer span.End()
7272

73-
ctx, err = ensureToken(ctx, signals)
73+
ctx, err = ensureToken(ctx, []string{"changes:read"}, signals)
7474
if err != nil {
7575
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
7676
"url": viper.GetString("url"),

cmd/getbookmark.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func GetBookmark(signals chan os.Signal, ready chan bool) int {
6060
))
6161
defer span.End()
6262

63-
ctx, err = ensureToken(ctx, signals)
63+
ctx, err = ensureToken(ctx, []string{"changes:read"}, signals)
6464
if err != nil {
6565
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
6666
"url": viper.GetString("url"),

cmd/getchange.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func GetChange(signals chan os.Signal, ready chan bool) int {
5454
))
5555
defer span.End()
5656

57-
ctx, err = ensureToken(ctx, signals)
57+
ctx, err = ensureToken(ctx, []string{"changes:read"}, signals)
5858
if err != nil {
5959
log.WithContext(ctx).WithFields(log.Fields{
6060
"url": viper.GetString("url"),
@@ -90,6 +90,7 @@ func GetChange(signals chan os.Signal, ready chan bool) int {
9090
log.WithContext(ctx).WithFields(log.Fields{
9191
"change-uuid": uuid.UUID(response.Msg.Change.Metadata.UUID),
9292
"change-created": response.Msg.Change.Metadata.CreatedAt.AsTime(),
93+
"change-status": response.Msg.Change.Metadata.Status.String(),
9394
"change-name": response.Msg.Change.Properties.Title,
9495
"change-description": response.Msg.Change.Properties.Description,
9596
}).Info("found change")

cmd/getsnapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func GetSnapshot(signals chan os.Signal, ready chan bool) int {
5959
))
6060
defer span.End()
6161

62-
ctx, err = ensureToken(ctx, signals)
62+
ctx, err = ensureToken(ctx, []string{"changes:read"}, signals)
6363
if err != nil {
6464
log.WithContext(ctx).WithError(err).WithFields(log.Fields{
6565
"url": viper.GetString("url"),

cmd/request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func Request(signals chan os.Signal, ready chan bool) int {
7474

7575
lf := log.Fields{}
7676

77-
ctx, err = ensureToken(ctx, signals)
77+
ctx, err = ensureToken(ctx, []string{"explore:read"}, signals)
7878
if err != nil {
7979
log.WithContext(ctx).WithFields(lf).WithField("api-key-url", viper.GetString("api-key-url")).WithError(err).Error("failed to authenticate")
8080
return 1

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func Execute() {
5757
}
5858

5959
// ensureToken
60-
func ensureToken(ctx context.Context, signals chan os.Signal) (context.Context, error) {
60+
func ensureToken(ctx context.Context, requiredScopes []string, signals chan os.Signal) (context.Context, error) {
6161
// get a token from the api key if present
6262
if viper.GetString("api-key") != "" {
6363
log.WithContext(ctx).Debug("using provided token for authentication")
@@ -97,7 +97,7 @@ func ensureToken(ctx context.Context, signals chan os.Signal) (context.Context,
9797
// Authenticate using the oauth resource owner password flow
9898
config := oauth2.Config{
9999
ClientID: viper.GetString("auth0-client-id"),
100-
Scopes: []string{"openid", "profile", "email", "gateway:stream", "request:send", "reverselink:request", "account:read", "source:read", "source:write", "api:read", "api:write", "gateway:objects"},
100+
Scopes: requiredScopes,
101101
Endpoint: oauth2.Endpoint{
102102
AuthURL: fmt.Sprintf("https://%v/authorize", viper.GetString("auth0-domain")),
103103
TokenURL: fmt.Sprintf("https://%v/oauth/token", viper.GetString("auth0-domain")),

cmd/startchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func StartChange(signals chan os.Signal, ready chan bool) int {
5252
))
5353
defer span.End()
5454

55-
ctx, err = ensureToken(ctx, signals)
55+
ctx, err = ensureToken(ctx, []string{"changes:write"},signals)
5656
if err != nil {
5757
log.WithContext(ctx).WithFields(log.Fields{
5858
"url": viper.GetString("url"),

0 commit comments

Comments
 (0)