Skip to content

Commit f429d61

Browse files
authored
Merge pull request #50 from rgritti/add-uid-in-context
adding identification for services/users
2 parents 584ad92 + 2469c51 commit f429d61

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

zalando/zalando.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func ScopeCheck(name string, scopes ...string) func(tc *ginoauth2.TokenContainer
137137
ctx.Set(s, cur) // set value from token of configured scope to the context, which you can use in your application.
138138
}
139139
}
140+
//Getting the uid for identification of the service calling
141+
if cur, ok := tc.Scopes["uid"]; ok {
142+
ctx.Set("uid", cur)
143+
}
140144
return len(scopesFromToken) > 0
141145
}
142146
}
@@ -158,6 +162,10 @@ func ScopeAndCheck(name string, scopes ...string) func(tc *ginoauth2.TokenContai
158162
return false
159163
}
160164
}
165+
//Getting the uid for identification of the service calling
166+
if cur, ok := tc.Scopes["uid"]; ok {
167+
ctx.Set("uid", cur)
168+
}
161169
return true
162170
}
163171
}

zalando/zalando_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func TestScopeCheck(t *testing.T) {
9595
scopeVal, scopeOk := ctx.Get("my-scope-1")
9696
assert.True(t, scopeOk)
9797
assert.Equal(t, true, scopeVal)
98+
99+
uid, uidOk := ctx.Get("uid")
100+
assert.True(t, uidOk)
101+
assert.Equal(t, "stups_marilyn-updater", uid)
98102
}
99103

100104
func TestScopeAndCheck(t *testing.T) {

0 commit comments

Comments
 (0)