Share via


AccountManager.GetAuthToken Method

Definition

Overloads

GetAuthToken(Account, String, Boolean, IAccountManagerCallback, Handler)
Obsolete.

Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials.

GetAuthToken(Account, String, Bundle, Activity, IAccountManagerCallback, Handler)

Gets an auth token of the specified type for a particular account, prompting the user for credentials if necessary.

GetAuthToken(Account, String, Bundle, Boolean, IAccountManagerCallback, Handler)

Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials.

GetAuthToken(Account, String, Boolean, IAccountManagerCallback, Handler)

Caution

deprecated

Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials.

[Android.Runtime.Register("getAuthToken", "(Landroid/accounts/Account;Ljava/lang/String;ZLandroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture;", "GetGetAuthToken_Landroid_accounts_Account_Ljava_lang_String_ZLandroid_accounts_AccountManagerCallback_Landroid_os_Handler_Handler")]
[Android.Runtime.RequiresPermission("android.permission.USE_CREDENTIALS")]
[System.Obsolete("deprecated")]
public virtual Android.Accounts.IAccountManagerFuture? GetAuthToken (Android.Accounts.Account? account, string? authTokenType, bool notifyAuthFailure, Android.Accounts.IAccountManagerCallback? callback, Android.OS.Handler? handler);
[<Android.Runtime.Register("getAuthToken", "(Landroid/accounts/Account;Ljava/lang/String;ZLandroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture;", "GetGetAuthToken_Landroid_accounts_Account_Ljava_lang_String_ZLandroid_accounts_AccountManagerCallback_Landroid_os_Handler_Handler")>]
[<Android.Runtime.RequiresPermission("android.permission.USE_CREDENTIALS")>]
[<System.Obsolete("deprecated")>]
abstract member GetAuthToken : Android.Accounts.Account * string * bool * Android.Accounts.IAccountManagerCallback * Android.OS.Handler -> Android.Accounts.IAccountManagerFuture
override this.GetAuthToken : Android.Accounts.Account * string * bool * Android.Accounts.IAccountManagerCallback * Android.OS.Handler -> Android.Accounts.IAccountManagerFuture

Parameters

account
Account

The account to fetch an auth token for

authTokenType
String

The auth token type, an authenticator-dependent string token, must not be null

notifyAuthFailure
Boolean

True to add a notification to prompt the user for a password if necessary, false to leave that to the caller

callback
IAccountManagerCallback

Callback to invoke when the request completes, null for no callback

handler
Handler

Handler identifying the callback thread, null for the main thread

Returns

An AccountManagerFuture which resolves to a Bundle with at least the following fields on success: <ul> <li> #KEY_ACCOUNT_NAME - the name of the account you supplied <li> #KEY_ACCOUNT_TYPE - the type of the account <li> #KEY_AUTHTOKEN - the auth token you wanted </ul>

        (Other authenticator-specific values may be returned.)  If the user
        must enter credentials, the returned Bundle contains only
        <code data-dev-comment-type="c">#KEY_INTENT</code> with the <code data-dev-comment-type="c">Intent</code> needed to launch a prompt.

        If an error occurred, <code data-dev-comment-type="c">AccountManagerFuture#getResult()</code> throws:
        &lt;ul&gt;
        &lt;li&gt; <code data-dev-comment-type="c">AuthenticatorException</code> if the authenticator failed to respond
        &lt;li&gt; <code data-dev-comment-type="c">OperationCanceledException</code> if the operation is canceled for
             any reason, incluidng the user canceling a credential request
        &lt;li&gt; <code data-dev-comment-type="c">IOException</code> if the authenticator experienced an I/O problem
             creating a new auth token, usually because of network trouble
        &lt;/ul&gt;
        If the account is no longer present on the device, the return value is
        authenticator-dependent.  The caller should verify the validity of the
        account before requesting an auth token.
Attributes

Remarks

Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials. This method is intended for background tasks and services where the user should not be immediately interrupted with a password prompt.

If a previously generated auth token is cached for this account and type, then it is returned. Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, an Intent is returned which, when started, will prompt the user for a password. If the notifyAuthFailure parameter is set, a status bar notification is also created with the same Intent, alerting the user that they need to enter a password at some point.

In that case, you may need to wait until the user responds, which could take hours or days or forever. When the user does respond and supply a new password, the account manager will broadcast the #LOGIN_ACCOUNTS_CHANGED_ACTION Intent and notify OnAccountsUpdateListener which applications can use to try again.

If notifyAuthFailure is not set, it is the application's responsibility to launch the returned Intent at some point. Either way, the result from this call will not wait for user action.

Some authenticators have auth token <em>types</em>, whose value is authenticator-dependent. Some services use different token types to access different functionality -- for example, Google uses different auth tokens to access Gmail and Google Calendar for the same account.

This method may be called from any thread, but the returned AccountManagerFuture must not be used on the main thread.

This member is deprecated. use #getAuthToken(Account, String, android.os.Bundle, boolean, AccountManagerCallback, android.os.Handler) instead

Java documentation for android.accounts.AccountManager.getAuthToken(android.accounts.Account, java.lang.String, boolean, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetAuthToken(Account, String, Bundle, Activity, IAccountManagerCallback, Handler)

Gets an auth token of the specified type for a particular account, prompting the user for credentials if necessary.

[Android.Runtime.Register("getAuthToken", "(Landroid/accounts/Account;Ljava/lang/String;Landroid/os/Bundle;Landroid/app/Activity;Landroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture;", "GetGetAuthToken_Landroid_accounts_Account_Ljava_lang_String_Landroid_os_Bundle_Landroid_app_Activity_Landroid_accounts_AccountManagerCallback_Landroid_os_Handler_Handler")]
[Android.Runtime.RequiresPermission("android.permission.USE_CREDENTIALS")]
public virtual Android.Accounts.IAccountManagerFuture? GetAuthToken (Android.Accounts.Account? account, string? authTokenType, Android.OS.Bundle? options, Android.App.Activity? activity, Android.Accounts.IAccountManagerCallback? callback, Android.OS.Handler? handler);
[<Android.Runtime.Register("getAuthToken", "(Landroid/accounts/Account;Ljava/lang/String;Landroid/os/Bundle;Landroid/app/Activity;Landroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture;", "GetGetAuthToken_Landroid_accounts_Account_Ljava_lang_String_Landroid_os_Bundle_Landroid_app_Activity_Landroid_accounts_AccountManagerCallback_Landroid_os_Handler_Handler")>]
[<Android.Runtime.RequiresPermission("android.permission.USE_CREDENTIALS")>]
abstract member GetAuthToken : Android.Accounts.Account * string * Android.OS.Bundle * Android.App.Activity * Android.Accounts.IAccountManagerCallback * Android.OS.Handler -> Android.Accounts.IAccountManagerFuture
override this.GetAuthToken : Android.Accounts.Account * string * Android.OS.Bundle * Android.App.Activity * Android.Accounts.IAccountManagerCallback * Android.OS.Handler -> Android.Accounts.IAccountManagerFuture

Parameters

account
Account

The account to fetch an auth token for

authTokenType
String

The auth token type, an authenticator-dependent string token, must not be null

options
Bundle

Authenticator-specific options for the request, may be null or empty

activity
Activity

The Activity context to use for launching a new authenticator-defined sub-Activity to prompt the user for a password if necessary; used only to call startActivity(); must not be null.

callback
IAccountManagerCallback

Callback to invoke when the request completes, null for no callback

handler
Handler

Handler identifying the callback thread, null for the main thread

Returns

An AccountManagerFuture which resolves to a Bundle with at least the following fields: <ul> <li> #KEY_ACCOUNT_NAME - the name of the account you supplied <li> #KEY_ACCOUNT_TYPE - the type of the account <li> #KEY_AUTHTOKEN - the auth token you wanted </ul>

        (Other authenticator-specific values may be returned.)  If an auth token
        could not be fetched, <code data-dev-comment-type="c">AccountManagerFuture#getResult()</code> throws:
        &lt;ul&gt;
        &lt;li&gt; <code data-dev-comment-type="c">AuthenticatorException</code> if the authenticator failed to respond
        &lt;li&gt; <code data-dev-comment-type="c">OperationCanceledException</code> if the operation is canceled for
             any reason, incluidng the user canceling a credential request
        &lt;li&gt; <code data-dev-comment-type="c">IOException</code> if the authenticator experienced an I/O problem
             creating a new auth token, usually because of network trouble
        &lt;/ul&gt;
        If the account is no longer present on the device, the return value is
        authenticator-dependent.  The caller should verify the validity of the
        account before requesting an auth token.
Attributes

Remarks

Gets an auth token of the specified type for a particular account, prompting the user for credentials if necessary. This method is intended for applications running in the foreground where it makes sense to ask the user directly for a password.

If a previously generated auth token is cached for this account and type, then it is returned. Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, the user is prompted to enter a password.

Some authenticators have auth token <em>types</em>, whose value is authenticator-dependent. Some services use different token types to access different functionality -- for example, Google uses different auth tokens to access Gmail and Google Calendar for the same account.

<b>NOTE:</b> If targeting your app to work on API level 22 and before, USE_CREDENTIALS permission is needed for those platforms. See docs for this function in API level 22.

This method may be called from any thread, but the returned AccountManagerFuture must not be used on the main thread.

Java documentation for android.accounts.AccountManager.getAuthToken(android.accounts.Account, java.lang.String, android.os.Bundle, android.app.Activity, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetAuthToken(Account, String, Bundle, Boolean, IAccountManagerCallback, Handler)

Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials.

[Android.Runtime.Register("getAuthToken", "(Landroid/accounts/Account;Ljava/lang/String;Landroid/os/Bundle;ZLandroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture;", "GetGetAuthToken_Landroid_accounts_Account_Ljava_lang_String_Landroid_os_Bundle_ZLandroid_accounts_AccountManagerCallback_Landroid_os_Handler_Handler")]
[Android.Runtime.RequiresPermission("android.permission.USE_CREDENTIALS")]
public virtual Android.Accounts.IAccountManagerFuture? GetAuthToken (Android.Accounts.Account? account, string? authTokenType, Android.OS.Bundle? options, bool notifyAuthFailure, Android.Accounts.IAccountManagerCallback? callback, Android.OS.Handler? handler);
[<Android.Runtime.Register("getAuthToken", "(Landroid/accounts/Account;Ljava/lang/String;Landroid/os/Bundle;ZLandroid/accounts/AccountManagerCallback;Landroid/os/Handler;)Landroid/accounts/AccountManagerFuture;", "GetGetAuthToken_Landroid_accounts_Account_Ljava_lang_String_Landroid_os_Bundle_ZLandroid_accounts_AccountManagerCallback_Landroid_os_Handler_Handler")>]
[<Android.Runtime.RequiresPermission("android.permission.USE_CREDENTIALS")>]
abstract member GetAuthToken : Android.Accounts.Account * string * Android.OS.Bundle * bool * Android.Accounts.IAccountManagerCallback * Android.OS.Handler -> Android.Accounts.IAccountManagerFuture
override this.GetAuthToken : Android.Accounts.Account * string * Android.OS.Bundle * bool * Android.Accounts.IAccountManagerCallback * Android.OS.Handler -> Android.Accounts.IAccountManagerFuture

Parameters

account
Account

The account to fetch an auth token for

authTokenType
String

The auth token type, an authenticator-dependent string token, must not be null

options
Bundle

Authenticator-specific options for the request, may be null or empty

notifyAuthFailure
Boolean

True to add a notification to prompt the user for a password if necessary, false to leave that to the caller

callback
IAccountManagerCallback

Callback to invoke when the request completes, null for no callback

handler
Handler

Handler identifying the callback thread, null for the main thread

Returns

An AccountManagerFuture which resolves to a Bundle with at least the following fields on success: <ul> <li> #KEY_ACCOUNT_NAME - the name of the account you supplied <li> #KEY_ACCOUNT_TYPE - the type of the account <li> #KEY_AUTHTOKEN - the auth token you wanted </ul>

        (Other authenticator-specific values may be returned.)  If the user
        must enter credentials, the returned Bundle contains only
        <code data-dev-comment-type="c">#KEY_INTENT</code> with the <code data-dev-comment-type="c">Intent</code> needed to launch a prompt.

        If an error occurred, <code data-dev-comment-type="c">AccountManagerFuture#getResult()</code> throws:
        &lt;ul&gt;
        &lt;li&gt; <code data-dev-comment-type="c">AuthenticatorException</code> if the authenticator failed to respond
        &lt;li&gt; <code data-dev-comment-type="c">OperationCanceledException</code> if the operation is canceled for
             any reason, incluidng the user canceling a credential request
        &lt;li&gt; <code data-dev-comment-type="c">IOException</code> if the authenticator experienced an I/O problem
             creating a new auth token, usually because of network trouble
        &lt;/ul&gt;
        If the account is no longer present on the device, the return value is
        authenticator-dependent.  The caller should verify the validity of the
        account before requesting an auth token.
Attributes

Remarks

Gets an auth token of the specified type for a particular account, optionally raising a notification if the user must enter credentials. This method is intended for background tasks and services where the user should not be immediately interrupted with a password prompt.

If a previously generated auth token is cached for this account and type, then it is returned. Otherwise, if a saved password is available, it is sent to the server to generate a new auth token. Otherwise, an Intent is returned which, when started, will prompt the user for a password. If the notifyAuthFailure parameter is set, a status bar notification is also created with the same Intent, alerting the user that they need to enter a password at some point.

In that case, you may need to wait until the user responds, which could take hours or days or forever. When the user does respond and supply a new password, the account manager will broadcast the #LOGIN_ACCOUNTS_CHANGED_ACTION Intent and notify OnAccountsUpdateListener which applications can use to try again.

If notifyAuthFailure is not set, it is the application's responsibility to launch the returned Intent at some point. Either way, the result from this call will not wait for user action.

Some authenticators have auth token <em>types</em>, whose value is authenticator-dependent. Some services use different token types to access different functionality -- for example, Google uses different auth tokens to access Gmail and Google Calendar for the same account.

This method may be called from any thread, but the returned AccountManagerFuture must not be used on the main thread.

<b>NOTE:</b> If targeting your app to work on API level 22 and before, USE_CREDENTIALS permission is needed for those platforms. See docs for this function in API level 22.

Java documentation for android.accounts.AccountManager.getAuthToken(android.accounts.Account, java.lang.String, android.os.Bundle, boolean, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to