从openshift获取承载令牌的Rest端点

从openshift获取承载令牌的Rest端点,openshift,redhat,kubernetes-helm,Openshift,Redhat,Kubernetes Helm,我正在尝试使用openshift中的REST端点,例如获取POD/部署等。为了访问这些端点,我需要承载令牌。我正试图找出将返回承载令牌的剩余端点 我用了curl-u-un:pwd-kI“ 但它没有把代币还给我。有人能帮我吗?获取承载令牌是openshift中的两个步骤 您可以获得如下所示的令牌 public static String getUserToken(String domain, String userName, String password) { String u

我正在尝试使用openshift中的REST端点,例如获取POD/部署等。为了访问这些端点,我需要承载令牌。我正试图找出将返回承载令牌的剩余端点

我用了curl-u-un:pwd-kI“


但它没有把代币还给我。有人能帮我吗?

获取承载令牌是openshift中的两个步骤

您可以获得如下所示的令牌

    public static String getUserToken(String domain, String userName, String password) {

    String userToken = "401";
    String path = ".well-known/oauth-authorization-server";

    try {
        String command = domain.trim() + "/" + path.trim();
        CloseableHttpClient client = OpenshiftSessionUtil.custom();        
        String reqType = "GET";
        HttpUriRequest request = RequestBuilder.create(reqType).setUri(command).build();
        request.addHeader("Accept", "application/json");
        HttpResponse response = client.execute(request);

        String authorization_endpoint = OpenshiftSessionUtil.getPropertyFromHttpResponse(response,
                "authorization_endpoint");

        if (authorization_endpoint != null) {
            //System.out.println(" UserTokenUtil::getUserToken " + authorization_endpoint);
            CredentialsProvider provider = new BasicCredentialsProvider();
            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password);
            provider.setCredentials(AuthScope.ANY, credentials);
             client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider)
                    .setSSLContext(SSLHandler.getSSLContextToSkipVerification()).disableRedirectHandling().build();
            String tokenURL = authorization_endpoint.trim()
                    + "?client_id=openshift-challenging-client&response_type=token";
            HttpGet httpGet_Token = new HttpGet(tokenURL);
            httpGet_Token.setHeader("X-Csrf-Token", "1");
            httpGet_Token.setHeader("Content-Type", "application/json");
            httpGet_Token.setHeader("Accept", "*/*");
            HttpResponse httpGet_Token_Response = client.execute(httpGet_Token);
            if (httpGet_Token_Response.getStatusLine().getStatusCode() == 302) {
                Header[] headers = httpGet_Token_Response.getAllHeaders();
                String location_Val = null;
                for (Header header : headers) {
                    if (header.getName().trim().equals("Location")) {
                        System.out.println(" UserTokenUtil::getUserToken Location Found!");
                        location_Val = header.getValue();
                        break;
                    }
                }

                Pattern pattern = Pattern.compile("access_token=[^&]*");
                Matcher matcher = pattern.matcher(location_Val);
                if (matcher.find()) {
                    System.out.println(" UserTokenUtil::getUserToken User Token Found");
                    userToken = matcher.group().split("=")[1];
                }

            } else if (httpGet_Token_Response.getStatusLine().getStatusCode() == 401) {
                System.out.println(" UserTokenUtil::getUserToken Unauthorized");
                userToken = "401";
            }

        }

    } catch (Exception e) {
        //logger
    }
    return userToken;
}

public static CloseableHttpClient custom() {
    SSLContext sslContext = SSLHandler.getSSLContextToSkipVerification();
    SSLConnectionSocketFactory sslConSocFactory = new SSLConnectionSocketFactory(sslContext,
            SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    HttpClientBuilder clientbuilder = HttpClients.custom();
    clientbuilder = clientbuilder.setSSLSocketFactory(sslConSocFactory);
    CloseableHttpClient client = clientbuilder.build();
    return client;
}