简体   繁体   中英

GitHub App Access Tokens API ERROR : Integration must generate a public key

I am working on GitHub Apps apis, Where i need to get the access tokens using jwt token for installations.

I was able to generate JWT token from private key using link , but when i tried to generate access token for the installation through Postman it says:

Request :

URL : https://api.github.com/app/installations/8/access_tokens

Authorization : Bearer (JWT token)

Accept : application/vnd.github.machine-man-preview+json

Response :

{
    "message": "Integration must generate a public key",
    "documentation_url": "https://developer.github.com/v3"
    }

And the code i used to generate JWT token is as below:

String privKeyStr = "myprivatekey";
            byte[] data = Base64.decodeBase64(privKeyStr);
            /* Add PKCS#8 formatting */
            ASN1EncodableVector v = new ASN1EncodableVector();
            v.add(new ASN1Integer(0));
            ASN1EncodableVector v2 = new ASN1EncodableVector();
            v2.add(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.rsaEncryption.getId()));
            v2.add(DERNull.INSTANCE);
            v.add(new DERSequence(v2));
            v.add(new DEROctetString(data));
            ASN1Sequence seq = new DERSequence(v);
            byte[] privKey = seq.getEncoded("DER");

            PKCS8EncodedKeySpec spec = new  PKCS8EncodedKeySpec(privKey);
            KeyFactory fact = KeyFactory.getInstance("RSA");
            PrivateKey key = fact.generatePrivate(spec);
            long nowMillis = System.currentTimeMillis();
            long expiremilis = 60000l*5l;
            Date now = new Date(nowMillis);

            Date expireDate = new Date(nowMillis+expiremilis); 

            //retStr = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.RS256,key).compact();
            String compactJws = Jwts.builder()
                    .setSubject("TestingApp")
                     .setIssuer("4")
                    .setIssuedAt(now)
                     .setExpiration(expireDate)
                     .signWith(SignatureAlgorithm.RS256,key)
                     .compact();
            System.out.println(compactJws);

I googled it , but unable to find the cause.

看起来这里唯一的问题是您需要将setIssuersetIssuer )设置为您的GitHub应用程序ID,可能不是4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM