• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / VCVerifier / 6729944358

02 Nov 2023 08:17AM UTC coverage: 54.042% (+2.2%) from 51.887%
6729944358

push

github

web-flow
Merge pull request #19 from FIWARE/ebsi_token

EBSI M2M Token endpoint

202 of 202 new or added lines in 7 files covered. (100.0%)

829 of 1534 relevant lines covered (54.04%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/openapi/api_auth.go
1
/*
2
 * Authorisation API
3
 *
4
 * The subset of the [Authentication API as defined by EBSI](https://api-pilot.ebsi.eu/docs/apis/authorisation/latest#/).
5
 *
6
 * API version: v4
7
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
8
 */
9
package openapi
10

11
import (
12
        "encoding/base64"
13
        "encoding/json"
14
        "net/http"
15
        "strings"
16

17
        "github.com/fiware/VCVerifier/logging"
18
        "github.com/gin-gonic/gin"
19
)
20

21
var ErrorMessageUnableToDecodeBody = ProblemDetails{Title: "Code not decode body.", Status: 400}
22

23
func GetTokenM2M(c *gin.Context) {
×
24
        var requestBody TokenRequestBody
×
25
        if err := c.BindJSON(&requestBody); err != nil {
×
26
                logging.Log().Error("Could not map request body", err)
×
27
                c.AbortWithStatusJSON(400, ErrorMessageUnableToDecodeBody)
×
28
                return
×
29
        }
×
30
        bytes, err := base64.RawURLEncoding.DecodeString(requestBody.VpToken)
×
31
        if err != nil {
×
32
                logging.Log().Infof("Was not able to decode the form string %s. Err: %v", requestBody.VpToken, err)
×
33
                c.AbortWithStatusJSON(400, ErrorMessageUnableToDecodeToken)
×
34
                return
×
35
        }
×
36
        var rawCredentials []map[string]interface{}
×
37

×
38
        err = json.Unmarshal(bytes, &rawCredentials)
×
39
        if err != nil {
×
40
                logging.Log().Infof("Was not able to decode the credentials from the token %s. Err: %v", requestBody.VpToken, err)
×
41
                c.AbortWithStatusJSON(400, ErrorMessageUnableToDecodeCredential)
×
42
                return
×
43
        }
×
44
        clientId := c.GetHeader("client_id")
×
45

×
46
        scopes := strings.Split(requestBody.Scope, ",")
×
47

×
48
        // Subject is empty since multiple VCs with different subjects can be provided
×
49
        expiration, signedToken, err := getApiVerifier().GenerateToken(clientId, "", clientId, scopes, rawCredentials)
×
50
        if err != nil {
×
51
                logging.Log().Error("Failure during generating M2M token", err)
×
52
                c.AbortWithStatusJSON(400, err)
×
53
                return
×
54
        }
×
55
        response := TokenResponse{"Bearer", float32(expiration), signedToken, requestBody.Scope, ""}
×
56
        logging.Log().Infof("Generated and signed token: %v", response)
×
57
        c.JSON(http.StatusOK, response)
×
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc