-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:auth filter #303
Merged
Merged
feat:auth filter #303
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
dc81628
feat:auth filter
baerwang d2cea76
style: test set request headers
baerwang 13f6ea1
Merge branch 'develop' into develop
baerwang b4a85f0
fix: go fmt
MasterKenway 74966a4
Merge pull request #1 from MasterKenway/feat/auth-filter
baerwang d4b7567
feat: upgrade golint version
MasterKenway 47f924e
Merge branch 'develop' into develop
mark4z 8592dc6
Merge pull request #2 from MasterKenway/feat/auth-filter
baerwang 4a85345
style: variable naming
baerwang 17cbc49
fix:variable naming
baerwang b6134f9
style:FromHeaders set default Authorization: Bearer <token>
baerwang 85af2ed
Merge branch 'develop' into develop
baerwang be9660b
feat:custom auth error msg
baerwang e6fbdcf
feat:springcloud integration auth filter
baerwang 350152c
Merge remote-tracking branch 'origin/develop' into develop
baerwang c28b5b8
fix:mod conflict
baerwang 0f9715f
Merge branch 'develop' into develop
baerwang fcc47bd
fix:go fmt
baerwang b6023dc
docs:auth filter
baerwang cb16ad0
style: clean up commented code
baerwang 64b35a3
add valid any/all function annotation
baerwang 9dec3a3
Merge branch 'develop' into develop
AlexStocks 839abf8
fix: valid router
baerwang f560714
Merge remote-tracking branch 'origin/develop' into develop
baerwang 8aa1ce0
Merge branch 'develop' into develop
baerwang c27ed56
style: not need to next
baerwang 7cd11ca
Merge branch 'develop' into develop
ztelur 3ad4abe
fix:inexplicable mod
baerwang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Auth Filter Quick Start | ||
|
||
## Http | ||
|
||
Start Zookeeper [Docker environment]: | ||
|
||
```bash | ||
cd samples/dubbogo/http/docker | ||
run docker-compose.yml/services | ||
``` | ||
|
||
Start Http [Go environment]: | ||
|
||
```bash | ||
go run samples/dubbogo/simple/jwt/server/server.go | ||
``` | ||
|
||
Start Pixiu: | ||
|
||
```bash | ||
go run cmd/pixiu/*.go gateway start -c samples/dubbogo/simple/jwt/pixiu/conf.yaml | ||
``` | ||
|
||
Call the server of Http by Pixiu : | ||
|
||
- default Authorization: Bearer <token> | ||
|
||
```bash | ||
curl -H "Authorization: Bearer eyJraWQiOiJlZThkNjI2ZCIsInR5cCI6IkpXVCIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJXZWlkb25nIiwiYXVkIjoiVGFzaHVhbiIsImlzcyI6Imp3a3Mtc2VydmljZS5hcHBzcG90LmNvbSIsImlhdCI6MTYzMTM2OTk1NSwianRpIjoiNDY2M2E5MTAtZWU2MC00NzcwLTgxNjktY2I3NDdiMDljZjU0In0.LwD65d5h6U_2Xco81EClMa_1WIW4xXZl8o4b7WzY_7OgPD2tNlByxvGDzP7bKYA9Gj--1mi4Q4li4CAnKJkaHRYB17baC0H5P9lKMPuA6AnChTzLafY6yf-YadA7DmakCtIl7FNcFQQL2DXmh6gS9J6TluFoCIXj83MqETbDWpL28o3XAD_05UP8VLQzH2XzyqWKi97mOuvz-GsDp9mhBYQUgN3csNXt2v2l-bUPWe19SftNej0cxddyGu06tXUtaS6K0oe0TTbaqc3hmfEiu5G0J8U6ztTUMwXkBvaknE640NPgMQJqBaey0E4u0txYgyvMvvxfwtcOrDRYqYPBnA" http://localhost:8888/user/pixiu | ||
``` | ||
|
||
result on console : | ||
|
||
```log | ||
{"message":"user","status":200} | ||
``` | ||
|
||
Token invalid | ||
|
||
```bash | ||
curl http://localhost:8888/health | ||
``` | ||
|
||
result on console : | ||
|
||
```log | ||
{"message":"token invalid","status":401} | ||
``` | ||
|
||
|
||
|
||
## Spring Cloud | ||
|
||
Start Nacos [Docker environment]: | ||
|
||
```bash | ||
cd samples/springcloud/docker | ||
run docker-compose.yml/services | ||
``` | ||
|
||
Start SpringCloud [Java environment]: | ||
|
||
```bash | ||
cd samples/springcloud/server | ||
|
||
# the port is 8074 | ||
run auth-service | ||
|
||
# the port is 8071 | ||
run user-service | ||
``` | ||
|
||
Start Pixiu: | ||
|
||
```bash | ||
go run cmd/pixiu/*.go gateway start -c samples/dubbogo/simple/jwt/pixiu/springcloud-conf.yaml | ||
``` | ||
|
||
Call the server of SpringCloud by Pixiu : | ||
|
||
- default Authorization: Bearer <token> | ||
|
||
```bash | ||
# the serviceId is `user-provider` | ||
curl -H "Authorization: Bearer eyJraWQiOiJlZThkNjI2ZCIsInR5cCI6IkpXVCIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJXZWlkb25nIiwiYXVkIjoiVGFzaHVhbiIsImlzcyI6Imp3a3Mtc2VydmljZS5hcHBzcG90LmNvbSIsImlhdCI6MTYzMTM2OTk1NSwianRpIjoiNDY2M2E5MTAtZWU2MC00NzcwLTgxNjktY2I3NDdiMDljZjU0In0.LwD65d5h6U_2Xco81EClMa_1WIW4xXZl8o4b7WzY_7OgPD2tNlByxvGDzP7bKYA9Gj--1mi4Q4li4CAnKJkaHRYB17baC0H5P9lKMPuA6AnChTzLafY6yf-YadA7DmakCtIl7FNcFQQL2DXmh6gS9J6TluFoCIXj83MqETbDWpL28o3XAD_05UP8VLQzH2XzyqWKi97mOuvz-GsDp9mhBYQUgN3csNXt2v2l-bUPWe19SftNej0cxddyGu06tXUtaS6K0oe0TTbaqc3hmfEiu5G0J8U6ztTUMwXkBvaknE640NPgMQJqBaey0E4u0txYgyvMvvxfwtcOrDRYqYPBnA" http://localhost:8888/user-service/echo/Pixiu | ||
|
||
# the serviceId is `auth-provider` | ||
curl -H "Authorization: Bearer eyJraWQiOiJlZThkNjI2ZCIsInR5cCI6IkpXVCIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJXZWlkb25nIiwiYXVkIjoiVGFzaHVhbiIsImlzcyI6Imp3a3Mtc2VydmljZS5hcHBzcG90LmNvbSIsImlhdCI6MTYzMTM2OTk1NSwianRpIjoiNDY2M2E5MTAtZWU2MC00NzcwLTgxNjktY2I3NDdiMDljZjU0In0.LwD65d5h6U_2Xco81EClMa_1WIW4xXZl8o4b7WzY_7OgPD2tNlByxvGDzP7bKYA9Gj--1mi4Q4li4CAnKJkaHRYB17baC0H5P9lKMPuA6AnChTzLafY6yf-YadA7DmakCtIl7FNcFQQL2DXmh6gS9J6TluFoCIXj83MqETbDWpL28o3XAD_05UP8VLQzH2XzyqWKi97mOuvz-GsDp9mhBYQUgN3csNXt2v2l-bUPWe19SftNej0cxddyGu06tXUtaS6K0oe0TTbaqc3hmfEiu5G0J8U6ztTUMwXkBvaknE640NPgMQJqBaey0E4u0txYgyvMvvxfwtcOrDRYqYPBnA" http://localhost:8888/auth-service/echo/Pixiu | ||
``` | ||
|
||
result on console : | ||
|
||
```log | ||
Hello {service_name} Pixiu | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package jwt | ||
|
||
import "github.com/MicahParks/keyfunc" | ||
|
||
type ( | ||
// FromHeaders Get the token from a field in the header,default Authorization: Bearer <token> | ||
FromHeaders struct { | ||
Name string `default:"Authorization" yaml:"name" json:"name" mapstructure:"name"` | ||
ValuePrefix string `default:"Bearer " yaml:"value_prefix" json:"value_prefix" mapstructure:"value_prefix"` | ||
} | ||
|
||
Rules struct { | ||
Match Match `yaml:"match" json:"match" mapstructure:"match"` | ||
Requires Requires `yaml:"requires" json:"requires" mapstructure:"requires"` | ||
} | ||
|
||
Match struct { | ||
Prefix string `yaml:"prefix" json:"prefix" mapstructure:"prefix"` | ||
} | ||
|
||
Requires struct { | ||
RequiresAny Requirement `yaml:"requires_any" json:"requires_any" mapstructure:"requires_any"` | ||
RequiresAll []Requirement `yaml:"requires_all" json:"requires_all" mapstructure:"requires_all"` | ||
} | ||
|
||
Requirement struct { | ||
ProviderName string `yaml:"provider_name" json:"provider_name" mapstructure:"provider_name"` | ||
} | ||
|
||
Providers struct { | ||
Name string `yaml:"name" json:"name" mapstructure:"name"` | ||
ForwardPayloadHeader string `yaml:"forward_payload_header" json:"forward_payload_header" mapstructure:"forward_payload_header"` | ||
FromHeaders FromHeaders `yaml:"from_headers" json:"from_headers" mapstructure:"from_headers"` | ||
Issuer string `yaml:"issuer" json:"issuer" mapstructure:"issuer"` | ||
Local *Local `yaml:"local_jwks" json:"local_jwks" mapstructure:"local_jwks"` | ||
Remote *Remote `yaml:"remote_jwks" json:"remote_jwks" mapstructure:"remote_jwks"` | ||
} | ||
|
||
Local struct { | ||
InlineString string `yaml:"inline_string" json:"inline_string" mapstructure:"inline_string"` | ||
} | ||
|
||
Remote struct { | ||
HttpURI HttpURI `yaml:"http_uri" json:"http_uri" mapstructure:"http_uri"` | ||
} | ||
|
||
HttpURI struct { | ||
Uri string `yaml:"uri" json:"uri" mapstructure:"uri"` | ||
Cluster string `yaml:"cluster" json:"cluster" mapstructure:"cluster"` | ||
TimeOut string `default:"5s" yaml:"timeout" json:"timeout" mapstructure:"timeout"` | ||
} | ||
) | ||
|
||
type Provider struct { | ||
jwk *keyfunc.JWKs | ||
issuer string | ||
forwardPayloadHeader string | ||
headers FromHeaders | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// indirect
It's necessary?