GenerateKiteKey
(k *KiteKey, keys *KeyPair)
| 99 | |
| 100 | // GenerateKiteKey |
| 101 | func GenerateKiteKey(k *KiteKey, keys *KeyPair) (*jwt.Token, error) { |
| 102 | var err error |
| 103 | |
| 104 | if keys == nil { |
| 105 | keys, err = GenerateKeyPair() |
| 106 | if err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | kiteKey := jwt.New(jwt.GetSigningMethod("RS256")) |
| 112 | |
| 113 | kiteKey.Claims = jwt.MapClaims{ |
| 114 | "iss": k.issuer(), |
| 115 | "sub": k.username(), |
| 116 | "iat": k.issuedAt(), |
| 117 | "jti": k.id(), |
| 118 | "kontrolURL": k.kontrolURL(), |
| 119 | "kontrolKey": string(keys.Public), |
| 120 | } |
| 121 | |
| 122 | privateKey, err := jwt.ParseRSAPrivateKeyFromPEM(keys.Private) |
| 123 | if err != nil { |
| 124 | return nil, err |
| 125 | } |
| 126 | |
| 127 | kiteKey.Raw, err = kiteKey.SignedString(privateKey) |
| 128 | if err != nil { |
| 129 | return nil, err |
| 130 | } |
| 131 | |
| 132 | kiteKey.Valid = true |
| 133 | |
| 134 | return kiteKey, nil |
| 135 | } |
| 136 | |
| 137 | // TokenExtractor is used to extract kite ID from the given JWT token. |
| 138 | type TokenExtractor struct { |
nothing calls this directly
no test coverage detected