Пример #1
0
        public override void AddPromptBehaviorQueryParameter(IPlatformParameters parameters, DictionaryRequestParameters authorizationRequestParameters)
        {
            PlatformParameters authorizationParameters = (parameters as PlatformParameters);

            if (authorizationParameters == null)
            {
                throw new ArgumentException("parameters should be of type PlatformParameters", "parameters");
            }

            PromptBehavior promptBehavior = (parameters as PlatformParameters).PromptBehavior;

            // ADFS currently ignores the parameter for now.
            switch (promptBehavior)
            {
            case PromptBehavior.Always:
                authorizationRequestParameters[OAuthParameter.Prompt] = PromptValue.Login;
                break;

            case PromptBehavior.RefreshSession:
                authorizationRequestParameters[OAuthParameter.Prompt] = PromptValue.RefreshSession;
                break;

            case PromptBehavior.Never:
                authorizationRequestParameters[OAuthParameter.Prompt] = PromptValue.AttemptNone;
                break;
            }
        }
        public IWebUI CreateAuthenticationDialog(IPlatformParameters inputParameters)
        {
            this.parameters = inputParameters as PlatformParameters;
            if (this.parameters == null)
            {
                throw new ArgumentException("parameters should be of type PlatformParameters", "parameters");
            }

            switch (this.parameters.PromptBehavior)
            {
            case PromptBehavior.Auto:
                return(new InteractiveWebUI {
                    OwnerWindow = this.parameters.OwnerWindow
                });

            case PromptBehavior.Always:
            case PromptBehavior.RefreshSession:
                return(new InteractiveWebUI {
                    OwnerWindow = this.parameters.OwnerWindow
                });

            case PromptBehavior.Never:
                return(new SilentWebUI {
                    OwnerWindow = this.parameters.OwnerWindow
                });

            default:
                throw new InvalidOperationException("Unexpected PromptBehavior value");
            }
        }
 public WebUI(IPlatformParameters parameters)
 {
     this.parameters = parameters as PlatformParameters;
     if (this.parameters == null)
     {
         throw new ArgumentException("parameters should be of type PlatformParameters", "parameters");
     }
 }
Пример #4
0
        private bool WillUseBroker()
        {
            PlatformParameters pp = PlatformParameters as PlatformParameters;

            if (pp != null)
            {
                return(pp.UseBroker);
            }

            return(false);
        }
Пример #5
0
        public override bool GetCacheLoadPolicy(IPlatformParameters parameters)
        {
            PlatformParameters authorizationParameters = (parameters as PlatformParameters);

            if (authorizationParameters == null)
            {
                throw new ArgumentException("parameters should be of type PlatformParameters", "parameters");
            }

            PromptBehavior promptBehavior = (parameters as PlatformParameters).PromptBehavior;

            return(promptBehavior != PromptBehavior.Always && promptBehavior != PromptBehavior.RefreshSession);
        }
Пример #6
0
        public void AcquireToken(IDictionary <string, string> brokerPayload)
        {
            if (brokerPayload.ContainsKey("broker_install_url"))
            {
                string url   = brokerPayload["broker_install_url"];
                Uri    uri   = new Uri(url);
                string query = uri.Query;
                if (query.StartsWith("?"))
                {
                    query = query.Substring(1);
                }

                Dictionary <string, string> keyPair = EncodingHelper.ParseKeyValueList(query, '&', true, false, null);

                PlatformParameters pp = PlatformParameters as PlatformParameters;
                pp.CallerActivity.StartActivity(new Intent(Intent.ActionView, Android.Net.Uri.Parse(keyPair["app_link"])));

                throw new AdalException(AdalErrorAndroidEx.BrokerApplicationRequired, AdalErrorMessageAndroidEx.BrokerApplicationRequired);
            }

            Context mContext = Application.Context;
            AuthenticationRequest request        = new AuthenticationRequest(brokerPayload);
            PlatformParameters    platformParams = PlatformParameters as PlatformParameters;

            // BROKER flow intercepts here
            // cache and refresh call happens through the authenticator service
            if (mBrokerProxy.VerifyUser(request.LoginHint,
                                        request.UserId))
            {
                PlatformPlugin.Logger.Verbose(null, "It switched to broker for context: " + mContext.PackageName);
                request.BrokerAccountName = request.LoginHint;

                // Don't send background request, if prompt flag is always or
                // refresh_session
                if (!string.IsNullOrEmpty(request.BrokerAccountName) || !string.IsNullOrEmpty(request.UserId))
                {
                    PlatformPlugin.Logger.Verbose(null, "User is specified for background token request");
                    resultEx = mBrokerProxy.GetAuthTokenInBackground(request, platformParams.CallerActivity);
                }
                else
                {
                    PlatformPlugin.Logger.Verbose(null, "User is not specified for background token request");
                }

                if (resultEx != null && resultEx.Result != null && !string.IsNullOrEmpty(resultEx.Result.AccessToken))
                {
                    PlatformPlugin.Logger.Verbose(null, "Token is returned from background call ");
                    readyForResponse.Release();
                    return;
                }

                // Launch broker activity
                // if cache and refresh request is not handled.
                // Initial request to authenticator needs to launch activity to
                // record calling uid for the account. This happens for Prompt auto
                // or always behavior.
                PlatformPlugin.Logger.Verbose(null, "Token is not returned from backgroud call");

                // Only happens with callback since silent call does not show UI
                PlatformPlugin.Logger.Verbose(null, "Launch activity for Authenticator");
                PlatformPlugin.Logger.Verbose(null, "Starting Authentication Activity");
                if (resultEx == null)
                {
                    PlatformPlugin.Logger.Verbose(null, "Initial request to authenticator");
                    // Log the initial request but not force a prompt
                }

                if (brokerPayload.ContainsKey("silent_broker_flow"))
                {
                    throw new AdalSilentTokenAcquisitionException();
                }

                // onActivityResult will receive the response
                // Activity needs to launch to record calling app for this
                // account
                Intent brokerIntent = mBrokerProxy.GetIntentForBrokerActivity(request, platformParams.CallerActivity);
                if (brokerIntent != null)
                {
                    try
                    {
                        PlatformPlugin.Logger.Verbose(null, "Calling activity pid:" + Android.OS.Process.MyPid()
                                                      + " tid:" + Android.OS.Process.MyTid() + "uid:"
                                                      + Android.OS.Process.MyUid());
                        platformParams.CallerActivity.StartActivityForResult(brokerIntent, 1001);
                    }
                    catch (ActivityNotFoundException e)
                    {
                        PlatformPlugin.Logger.Error(null, e);
                    }
                }
            }
            else
            {
                throw new AdalException(AdalErrorAndroidEx.NoBrokerAccountFound, "Add requested account as a Workplace account via Settings->Accounts or set UseBroker=true.");
            }
        }