2 // ========================LICENSE_START=================================
5 // Copyright (C) 2023: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
27 func (tokenReq AccessTokenReq) Validate() (bool, AccessTokenErr) {
29 if tokenReq.ClientId == "" {
30 return false, createAccessTokenError(AccessTokenErrErrorInvalidRequest, "Invalid request")
33 if tokenReq.GrantType != AccessTokenReqGrantTypeClientCredentials {
34 return false, createAccessTokenError(AccessTokenErrErrorInvalidGrant, "Invalid value for grant_type")
37 //3gpp#aefId1:apiName1,apiName2,…apiNameX;aefId2:apiName1,apiName2,…apiNameY;…aefIdN:apiName1,apiName2,…apiNameZ
38 if tokenReq.Scope != nil && *tokenReq.Scope != "" {
39 scope := strings.Split(*tokenReq.Scope, "#")
41 return false, createAccessTokenError(AccessTokenErrErrorInvalidScope, "Malformed scope")
43 if scope[0] != "3gpp" {
44 return false, createAccessTokenError(AccessTokenErrErrorInvalidScope, "Scope should start with 3gpp")
46 aefList := strings.Split(scope[1], ";")
47 for _, aef := range aefList {
48 apiList := strings.Split(aef, ":")
50 return false, createAccessTokenError(AccessTokenErrErrorInvalidScope, "Malformed scope")
54 return true, AccessTokenErr{}
57 func createAccessTokenError(err AccessTokenErrError, message string) AccessTokenErr {
58 return AccessTokenErr{
60 ErrorDescription: &message,