-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2821 from tharindu1st/go-enforcer
fix graphql invocation
- Loading branch information
Showing
12 changed files
with
268 additions
and
148 deletions.
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
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,27 @@ | ||
package authentication | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/wso2/apk/gateway/enforcer/internal/dto" | ||
"github.com/wso2/apk/gateway/enforcer/internal/requestconfig" | ||
"github.com/wso2/apk/gateway/enforcer/internal/transformer" | ||
) | ||
|
||
// ValidateToken validates the JWT token. | ||
func ValidateToken(rch *requestconfig.Holder, jwtTransformer *transformer.JWTTransformer) *dto.ImmediateResponse { | ||
if rch != nil { | ||
if rch.ExternalProcessingEnvoyMetadata.JwtAuthenticationData != nil { | ||
jwtValidationInfo := jwtTransformer.TransformJWTClaims(rch.MatchedAPI.OrganizationID, rch.ExternalProcessingEnvoyMetadata.JwtAuthenticationData) | ||
if jwtValidationInfo != nil { | ||
if jwtValidationInfo.Valid { | ||
rch.JWTValidationInfo = jwtValidationInfo | ||
return nil | ||
} | ||
} | ||
} | ||
} | ||
errorResponse := &dto.ErrorResponse{ErrorMessage: "Invalid Credentials", Code: "900901", ErrorDescription: "Make sure you have provided the correct security credentials"} | ||
jsonData, _ := json.MarshalIndent(errorResponse, "", " ") | ||
return &dto.ImmediateResponse{StatusCode: 401, Message: string(jsonData)} | ||
} |
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,24 @@ | ||
/* | ||
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* Licensed 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 dto | ||
|
||
// ErrorResponse represents the error response. | ||
type ErrorResponse struct { | ||
ErrorMessage string `json:"error_message"` | ||
Code string `json:"code"` | ||
ErrorDescription string `json:"error_description"` | ||
} |
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 |
---|---|---|
@@ -1,11 +1,33 @@ | ||
/* | ||
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* Licensed 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 dto | ||
|
||
// JWTValidationInfo represents the JWT validation info | ||
type JWTValidationInfo struct { | ||
Issuer string `json:"issuer"` // Issuer | ||
ClientID string `json:"clientId"` // Client ID | ||
Subject string `json:"subject"` // Subject | ||
Audiences []string `json:"audiences"` // Audiences | ||
Scopes []string `json:"scopes"` // Scopes | ||
Claims map[string]interface{} `json:"claims"` // Claims | ||
Valid bool `json:"valid"` // Valid | ||
ExpiryTime int64 `json:"expiryTime"` // Expiry time | ||
IssuedTime int64 `json:"issuedTime"` // Issued time | ||
JTI string `json:"jti"` // JTI | ||
ValidationCode int `json:"validationCode"` // Validation code | ||
ValidationMessage string `json:"validationMessage"` // Validation message | ||
Issuer string `json:"issuer"` // Issuer | ||
ClientID string `json:"clientId"` // Client ID | ||
Subject string `json:"subject"` // Subject | ||
Audiences []string `json:"audiences"` // Audiences | ||
Scopes []string `json:"scopes"` // Scopes | ||
Claims map[string]interface{} `json:"claims"` // Claims | ||
} |
Oops, something went wrong.