Search in sources :

Example 1 with AuthScope

use of cz.msebera.android.httpclient.auth.AuthScope in project android-async-http by loopj.

the class PreemptiveAuthorizationHttpRequestInterceptor method process.

public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
    CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
    HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    if (authState.getAuthScheme() == null) {
        AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
        Credentials creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            authState.setAuthScheme(new BasicScheme());
            authState.setCredentials(creds);
        }
    }
}
Also used : BasicScheme(cz.msebera.android.httpclient.impl.auth.BasicScheme) AuthState(cz.msebera.android.httpclient.auth.AuthState) HttpHost(cz.msebera.android.httpclient.HttpHost) AuthScope(cz.msebera.android.httpclient.auth.AuthScope) CredentialsProvider(cz.msebera.android.httpclient.client.CredentialsProvider) Credentials(cz.msebera.android.httpclient.auth.Credentials)

Example 2 with AuthScope

use of cz.msebera.android.httpclient.auth.AuthScope in project android-async-http by loopj.

the class DigestAuthSample method setCredentials.

private void setCredentials(AsyncHttpClient client, String URL) {
    Uri parsed = Uri.parse(URL);
    client.clearCredentialsProvider();
    client.setCredentials(new AuthScope(parsed.getHost(), parsed.getPort() == -1 ? 80 : parsed.getPort()), new UsernamePasswordCredentials(usernameField.getText().toString(), passwordField.getText().toString()));
}
Also used : AuthScope(cz.msebera.android.httpclient.auth.AuthScope) Uri(android.net.Uri) UsernamePasswordCredentials(cz.msebera.android.httpclient.auth.UsernamePasswordCredentials)

Aggregations

AuthScope (cz.msebera.android.httpclient.auth.AuthScope)2 Uri (android.net.Uri)1 HttpHost (cz.msebera.android.httpclient.HttpHost)1 AuthState (cz.msebera.android.httpclient.auth.AuthState)1 Credentials (cz.msebera.android.httpclient.auth.Credentials)1 UsernamePasswordCredentials (cz.msebera.android.httpclient.auth.UsernamePasswordCredentials)1 CredentialsProvider (cz.msebera.android.httpclient.client.CredentialsProvider)1 BasicScheme (cz.msebera.android.httpclient.impl.auth.BasicScheme)1