当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationContext.acquireToken方法代码示例

本文整理汇总了Java中com.microsoft.aad.adal.AuthenticationContext.acquireToken方法的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationContext.acquireToken方法的具体用法?Java AuthenticationContext.acquireToken怎么用?Java AuthenticationContext.acquireToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.aad.adal.AuthenticationContext的用法示例。


在下文中一共展示了AuthenticationContext.acquireToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: login

import com.microsoft.aad.adal.AuthenticationContext; //导入方法依赖的package包/类
private void login() {
    String authority = mAppPrefs.getString(Constants.AUTHORITY,"");
    if (!authority.equals("")) {
        try {

            mAuthContext = new AuthenticationContext(SetupActivity.this, authority, false);
            mProgressDialog.show();

            // use the endpoint that the user entered in and use the username,
            // as the hint that is automatically populated into the azure library's webview
            mAuthContext.acquireToken(
                    SetupActivity.this,
                    mEndpoint,
                    Constants.CLIENT_ID,
                    Constants.REDIRECT_URI,
                    mUsername,
                    this
            );
        } catch (Exception ex) {
            ex.getCause().printStackTrace();
        }
    }
    else {
        Toast.makeText(this, getString(R.string.authority_error), Toast.LENGTH_LONG).show();
    }
}
 
开发者ID:DynamicsCRM,项目名称:Android-Activity-Tracker-for-Dynamics-CRM,代码行数:27,代码来源:SetupActivity.java

示例2: initialize

import com.microsoft.aad.adal.AuthenticationContext; //导入方法依赖的package包/类
/**
 * Description: Calls AuthenticationContext.acquireToken(...) once to initialize with
 * user's credentials and avoid interactive prompt on later calls.
 * If all tokens expire, app must call initialize() again to prompt user interactively and
 * set up authentication context.
 *
 * @return A signal to wait on before continuing execution.
 */
public SettableFuture<AuthenticationResult> initialize() {

    final SettableFuture<AuthenticationResult> result = SettableFuture.create();

    if (verifyAuthenticationContext()) {
        AuthenticationContext authContext = getAuthenticationContext();
        if (authContext != null)
            authContext.acquireToken(
                    this.contextActivity,
                    this.resourceId,
                    Constants.CLIENT_ID,
                    Constants.REDIRECT_URI,
                    PromptBehavior.Auto,
                    new AuthenticationCallback<AuthenticationResult>() {

                        @Override
                        public void onSuccess(final AuthenticationResult authenticationResult) {

                            if (authenticationResult != null && authenticationResult.getStatus() == AuthenticationStatus.Succeeded) {
                                dependencyResolver = new ADALDependencyResolver(
                                        getAuthenticationContext(),
                                        resourceId,
                                        Constants.CLIENT_ID);
                                O365ServicesManager.initialize(authenticationResult.getTenantId());
                                result.set(authenticationResult);
                            }
                        }

                        @Override
                        public void onError(Exception t) {
                            result.setException(t);
                        }
                    }
            );
        else
            result.setException(new Throwable("Auth context verification failed. Did you set a context activity?"));
    } else {
        result.setException(new Throwable("Auth context verification failed. Did you set a context activity?"));
    }
    return result;
}
 
开发者ID:OfficeDev,项目名称:O365-Android-Snippets,代码行数:50,代码来源:AuthenticationController.java

示例3: onCreate

import com.microsoft.aad.adal.AuthenticationContext; //导入方法依赖的package包/类
/**
 * Initializes the activity
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_to_do);
    setDefaultDate();
    Toast.makeText(getApplicationContext(), TAG + "LifeCycle: OnCreate", Toast.LENGTH_SHORT)
            .show();

    txtSummary = (TextView)findViewById(R.id.textViewTitle);
    txtSummary.setText("TODO Services");
    mProgressBar = (ProgressBar)findViewById(R.id.loadingProgressBar);

    // Initialize the progress bar
    mProgressBar.setVisibility(ProgressBar.GONE);

    mLoginProgressDialog = new ProgressDialog(this);
    mLoginProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mLoginProgressDialog.setMessage("Login in progress...");
    mLoginProgressDialog.show();
    refreshInProgress = false;

    // Ask for token and provide callback
    try {
        Utils.setupKeyForSample();
        mAuthContext = new AuthenticationContext(ToDoActivity.this, Constants.AUTHORITY_URL,
                false);
        mAuthContext.acquireToken(ToDoActivity.this, Constants.RESOURCE_ID,
                Constants.CLIENT_ID, Constants.REDIRECT_URL, Constants.USER_HINT,
                new AuthenticationCallback<AuthenticationResult>() {

                    @Override
                    public void onError(Exception exc) {
                        if (mLoginProgressDialog.isShowing()) {
                            mLoginProgressDialog.dismiss();
                        }
                        Toast.makeText(getApplicationContext(),
                                TAG + "getToken Error:" + exc.getMessage(), Toast.LENGTH_SHORT)
                                .show();
                        navigateToLogOut();
                    }

                    @Override
                    public void onSuccess(AuthenticationResult result) {
                        if (mLoginProgressDialog.isShowing()) {
                            mLoginProgressDialog.dismiss();
                        }

                        if (result != null && !result.getAccessToken().isEmpty()) {
                            setLocalToken(result);
                            sendRequest();
                        } else {
                            navigateToLogOut();
                        }
                    }
                });
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), "Encryption is failed", Toast.LENGTH_SHORT)
                .show();
    }

    Toast.makeText(getApplicationContext(), TAG + "done", Toast.LENGTH_SHORT).show();
}
 
开发者ID:AzureADQuickStarts,项目名称:B2C-NativeClient-Android,代码行数:66,代码来源:ToDoActivity.java


注:本文中的com.microsoft.aad.adal.AuthenticationContext.acquireToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。