我正在尝试从ADAL获取Bearer Access令牌。我的申请在Adal注册。主要问题是我从服务器获得了一个令牌。但应该是承载的令牌类型是NULL。我如何理解REDIRECT URI是一个随机URL。我认为我做对了一切。如果我用JAVA和C#做同样的事情,我会获得一个Bearer Token,但是使用android我得到一个没有Bearer Tokentype的令牌
static final String LOG_TAG = "AUTH";
String idToken;
String accessToken;
String TYPE;
AuthenticationContext authenticationContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.
ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
this.Login();
}
public void Login() {
// Create the authentication context.
authenticationContext = new AuthenticationContext(MainActivity.this,
AUTHORITY, true);
// Acquire tokens using necessary UI.
authenticationContext.acquireToken(MainActivity.this, GRAPH_RESOURCE, CLIENT_ID, REDIRECT_URI,
PromptBehavior.Always, new AuthenticationCallback<AuthenticationResult>() {
@Override
public void onSuccess(AuthenticationResult result) {
accessToken = result.getAccessToken();
TYPE = result.getAccessTokenType();
// Print tokens.
Log.d("LOG_TAG", "ID Token: " + idToken);
Log.d("LOG_TAG", "Access Token: " + accessToken);
Log.d("LOG_TAG", "Access Type: " + result.getAccessTokenType());
}
@Override
public void onError(Exception exc) {
// TODO: Handle error
}
});
}
public void click(View V) {
new getData().execute(accessToken);
}
public void onLoginClick(View V) {
this.Login();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Pass the activity result to the authentication context.
if (authenticationContext != null) {
authenticationContext.onActivityResult(requestCode, resultCode, data);
}
}