-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathAuthenticator.java
101 lines (88 loc) · 3.35 KB
/
Authenticator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (C) 2013 Polychrom Pty Ltd
//
// This program is licensed under the 3-clause "Modified" BSD license,
// see LICENSE file for full definition.
package com.polychrom.cordova;
import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.accounts.NetworkErrorException;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
public class Authenticator extends AbstractAccountAuthenticator
{
private final Context ctx;
public Authenticator(Context context)
{
super(context);
ctx = context;
}
@Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options)
{
throw new UnsupportedOperationException();
}
@Override
public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options)
{
return null;
}
@Override
public Bundle editProperties(AccountAuthenticatorResponse response, String accountType)
{
throw new UnsupportedOperationException();
}
@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) throws NetworkErrorException
{
// If the caller requested an authToken type we don't support, then
// return an error
/*if(authTokenType isn't a supported auth token type)
{
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ERROR_MESSAGE, "invalid authTokenType");
return result;
}*/
// Extract the username and password from the Account Manager, and ask
// the server for an appropriate AuthToken.
final AccountManager am = AccountManager.get(ctx);
final String password = am.getPassword(account);
if (password != null)
{
final String authToken = ""; /* TODO: Login with account.name and passwod */
if (!TextUtils.isEmpty(authToken))
{
final Bundle result = new Bundle();
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
return result;
}
}
//final Intent intent = null; // TODO: Login intent
//final Bundle bundle = new Bundle();
//bundle.putParcelable(AccountManager.KEY_INTENT, intent);
//return bundle;
return null;
}
@Override
public String getAuthTokenLabel(String authTokenType)
{
// null means we don't support multiple authToken types
return null;
}
@Override
public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features)
{
final Bundle result = new Bundle();
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false);
return result;
}
@Override
public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions)
{
return null;
}
}