Best way to get authToken in RequestInterceptor

72 views
Skip to first unread message

Satch

unread,
Aug 29, 2014, 11:08:53 AM8/29/14
to android-...@googlegroups.com
I'm completely confused on how this template flows. Using the AccountManager makes complete sense, but how do i get the auth token to include part of the header for calls requiring it ? I have tried to do the following, but i think it's completely the wrong way to go about it 


 @Override
    public void intercept(RequestFacade request) {

        // Add header to set content type of JSON
        request.addHeader("Content-Type", "application/json");

        // Add auth info to request header

        AccountManager accountManager = apiKeyProvider.getAccountManager();
        Account[] accounts = accountManager.getAccountsByType(Constants.Auth.BOOTSTRAP_ACCOUNT_TYPE);
        if (accounts.length != 0) {
            String token =
                    accountManager.peekAuthToken(accounts[0], Constants.Auth.AUTHTOKEN_TYPE);
            if (token != null) {
                    request.addHeader(Constants.Http.HEADER_AUTH_STRING,token);
            }
        }

        // Add the user agent to the request.
        request.addHeader("User-Agent", userAgentProvider.get());
    }
Reply all
Reply to author
Forward
0 new messages