public Token generatePersonalAccessToken()

in core/src/main/java/com/microsoft/alm/auth/pat/VsoAzureAuthority.java [47:82]


    public Token generatePersonalAccessToken(final URI targetUri, final Token accessToken,
                                             final VsoTokenScope tokenScope, final boolean requireCompactToken,
                                             final boolean shouldCreateGlobalToken, final String displayName) {

        Debug.Assert(targetUri != null, "The targetUri parameter is null");
        Debug.Assert(accessToken != null && !StringHelper.isNullOrWhiteSpace(accessToken.Value) && (accessToken.Type == TokenType.Access || accessToken.Type == TokenType.Federated), "The accessToken parameter is null or invalid");
        Debug.Assert(tokenScope != null, "The tokenScope parameter is invalid");

        logger.debug("VsoAzureAuthority::generatePersonalAccessToken");

        try {
            // TODO: 449524: create a `HttpClient` with a minimum number of redirects, default creds, and a reasonable timeout (access token generation seems to hang occasionally)
            final HttpClient client = Global.getHttpClientFactory().createHttpClient();
            logger.debug("   using token to acquire personal access token");
            accessToken.contributeHeader(client.getHeaders());

            if (shouldCreateGlobalToken || populateTokenTargetId(targetUri, accessToken)) {
                final URI requestUrl = createPersonalAccessTokenRequestUri(client, targetUri, requireCompactToken);

                final StringContent content = getAccessTokenRequestBody(accessToken, tokenScope,
                        shouldCreateGlobalToken, displayName);

                final String responseText = client.getPostResponseText(requestUrl, content);

                final Token token = parsePersonalAccessTokenFromJson(responseText);
                if (token != null) {
                    logger.debug("   personal access token acquisition succeeded.");
                }

                return token;
            }
        } catch (IOException e) {
            throw new Error(e);
        }
        return null;
    }