protected ServerAuthorizationCodeGrant doCreateCodeGrant(AuthorizationCodeRegistration reg)
     throws OAuthServiceException {
   ServerAuthorizationCodeGrant grant =
       new ServerAuthorizationCodeGrant(
           reg.getClient(), getCode(reg), getGrantLifetime(), getIssuedAt());
   grant.setApprovedScopes(getApprovedScopes(reg));
   grant.setAudience(reg.getAudience());
   grant.setClientCodeChallenge(reg.getClientCodeChallenge());
   grant.setSubject(reg.getSubject());
   grant.setRedirectUri(reg.getRedirectUri());
   return grant;
 }
 protected void saveAuthorizationGrant(ServerAuthorizationCodeGrant grant) {
   String encrypted = ModelEncryptionSupport.encryptCodeGrant(grant, key);
   grant.setCode(encrypted);
   grants.add(encrypted);
 }