-
Notifications
You must be signed in to change notification settings - Fork 14
/
internal_claims.go
62 lines (50 loc) · 1.52 KB
/
internal_claims.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright © 2019, Oracle and/or its affiliates.
package ociauth
// Do not edit this file. This is based on standard OCI GO SDK format
// Claim is a representation of a JWT claim
type InternalClaim struct {
Issuer string `json:"issuer"`
Key string `json:"key"`
Value string `json:"value"`
}
// These constants define types of principal
const (
PrincipalTypeUser = "user"
PrincipalTypeInstance = "instance"
)
// This constant defines the Principal type key
var (
ClaimPrincipalType = "ptype"
)
// Claims represents a collection of JWT claims
type InternalClaims map[string][]InternalClaim
// FromClaims takes in a list of claims and coverts it to InternalClaims
func FromClaims(claimList []Claim) InternalClaims {
outputMap := make(map[string][]InternalClaim)
for _, item := range claimList {
internalClaim := FromClaim(item)
outputMap[internalClaim.Key] = append(outputMap[internalClaim.Key], internalClaim)
}
return outputMap
}
// FromClaims takes in a claim and coverts it to an InternalClaim
func FromClaim(claim Claim) InternalClaim {
return InternalClaim{
Issuer: *claim.Issuer,
Key: *claim.Key,
Value: *claim.Value,
}
}
// GetSingleClaim returns single claim given a claim type.
func (c InternalClaims) GetSingleClaim(key string) InternalClaim {
claims := c[key]
if len(claims) > 0 {
return claims[0]
}
return InternalClaim{}
}
// GetString returns the claim value given a claim type.
func (c InternalClaims) GetString(key string) string {
claim := c.GetSingleClaim(key)
return claim.Value
}