FileDocCategorySizeDatePackage
AndroidAuthenticator.javaAPI DocAndroid 5.1 API3682Thu Mar 12 22:22:56 GMT 2015com.android.volley.toolbox

AndroidAuthenticator

public class AndroidAuthenticator extends Object implements Authenticator
An Authenticator that uses {@link AccountManager} to get auth tokens of a specified type for a specified account.

Fields Summary
private final android.content.Context
mContext
private final android.accounts.Account
mAccount
private final String
mAuthTokenType
private final boolean
mNotifyAuthFailure
Constructors Summary
public AndroidAuthenticator(android.content.Context context, android.accounts.Account account, String authTokenType)
Creates a new authenticator.

param
context Context for accessing AccountManager
param
account Account to authenticate as
param
authTokenType Auth token type passed to AccountManager

        this(context, account, authTokenType, false);
    
public AndroidAuthenticator(android.content.Context context, android.accounts.Account account, String authTokenType, boolean notifyAuthFailure)
Creates a new authenticator.

param
context Context for accessing AccountManager
param
account Account to authenticate as
param
authTokenType Auth token type passed to AccountManager
param
notifyAuthFailure Whether to raise a notification upon auth failure

        mContext = context;
        mAccount = account;
        mAuthTokenType = authTokenType;
        mNotifyAuthFailure = notifyAuthFailure;
    
Methods Summary
public android.accounts.AccountgetAccount()
Returns the Account being used by this authenticator.

        return mAccount;
    
public java.lang.StringgetAuthToken()

        final AccountManager accountManager = AccountManager.get(mContext);
        AccountManagerFuture<Bundle> future = accountManager.getAuthToken(mAccount,
                mAuthTokenType, mNotifyAuthFailure, null, null);
        Bundle result;
        try {
            result = future.getResult();
        } catch (Exception e) {
            throw new AuthFailureError("Error while retrieving auth token", e);
        }
        String authToken = null;
        if (future.isDone() && !future.isCancelled()) {
            if (result.containsKey(AccountManager.KEY_INTENT)) {
                Intent intent = result.getParcelable(AccountManager.KEY_INTENT);
                throw new AuthFailureError(intent);
            }
            authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
        }
        if (authToken == null) {
            throw new AuthFailureError("Got null auth token for type: " + mAuthTokenType);
        }

        return authToken;
    
public voidinvalidateAuthToken(java.lang.String authToken)

        AccountManager.get(mContext).invalidateAuthToken(mAccount.type, authToken);