https://github.com/SonicRoshan/scope
Easily Manage OAuth2 Scopes In Go
https://github.com/SonicRoshan/scope
Last synced: 14 days ago
JSON representation
Easily Manage OAuth2 Scopes In Go
- Host: GitHub
- URL: https://github.com/SonicRoshan/scope
- Owner: ThundR67
- License: mit
- Created: 2019-09-23T10:48:14.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-25T13:48:05.000Z (almost 4 years ago)
- Last Synced: 2024-10-29T14:18:44.379Z (6 months ago)
- Language: Go
- Size: 9.77 KB
- Stars: 38
- Watchers: 1
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - scope - Easily Manage OAuth2 Scopes In Go. (Authentication and OAuth)
- awesome-go-plus - scope - Easily Manage OAuth2 Scopes In Go.  (Authentication and OAuth)
- fucking-awesome-go - scope - Easily Manage OAuth2 Scopes In Go. (Authentication and OAuth)
- awesome-go - scope - Easily Manage OAuth2 Scopes In Go. (Authentication and OAuth)
- awesome-go-with-stars - scope - Easily Manage OAuth2 Scopes In Go. (Authentication and OAuth)
- awesome-Char - scope - Easily Manage OAuth2 Scopes In Go. (Authentication and OAuth / Contents)
- awesome-go - scope - Easily Manage OAuth2 Scopes In Go. (Authentication and OAuth)
- awesome-go-cn - scope
- awesome-go - scope - Easily Manage OAuth2 Scopes In Go. (Authentication and OAuth)
- awesome-go-cn - scope
README
[](https://goreportcard.com/report/github.com/SonicRoshan/scope) [](https://godoc.org/github.com/SonicRoshan/scope) [](https://gocover.io/github.com/SonicRoshan/scope)
# Scope
Easily Manage OAuth2 Scopes In Go## Scope Matching Using Wildcard Strategy
```go
import "github.com/SonicRoshan/scope"scopeA := "read:user:*"
scopeB := "read:user:username"doesMatch := scope.MatchScopes(scopeA, scopeB)
```
This strategy will work like this :-
* `users.*` matches `users.read`
* `users.*` matches `users.read.foo`
* `users.read` matches `users.read`
* `users` does not match `users.read`
* `users.read.*` does not match `users.read`
* `users.*.*` does not match `users.read`
* `users.*.*` matches `users.read.own`
* `users.*.*` matches `users.read.own.other`
* `users.read.*` matches `users.read.own`
* `users.read.*` matches `users.read.own.other`
* `users.write.*` does not match `users.read.own`
* `users.*.bar` matches `users.baz.bar`
* `users.*.bar` does not `users.baz.baz.bar`## Filtering Struct For Read Request
When a client request certain data, this function will eliminate any data in the struct for which the client does not have a read scope.
```go
type user struct {
username string `readScope:"user:read:username"`
email string `readScope:"user:read:email"`
}func main() {
output := user{username : "Test", email : "[email protected]"}
scopesHeldByClient := []string{"user:read:username"}
scope.FilterRead(output, scopesHeldByClient)// Now output.email will be nil as client does not have scope required to read email field
output := user{username : "Test", email : "[email protected]"}
scopesHeldByClient := []string{"user:read:*"}
scope.FilterRead(&output, scopesHeldByClient)// Now none of the field in output will be nil as client has scopes to read everything in user struct
}```