/// <summary>
        /// Interactive request to acquire token for a given account, with the possibility of controlling the user experience, passing extra query
        /// parameters, providing extra scopes that the user can pre-consent to, and overriding the authority pre-configured in the application
        /// </summary>
        /// <param name="scopes">Scopes requested to access a protected API</param>
        /// <param name="account">Account to use for the interactive token acquisition. See <see cref="IAccount"/> for ways to get an account</param>
        /// <param name="behavior">Designed interactive experience for the user.</param>
        /// <param name="extraQueryParameters">This parameter will be appended as is to the query string in the HTTP authentication request to the authority.
        /// This is expected to be a string of segments of the form <c>key=value</c> separated by an ampersand character.
        /// The parameter can be null.</param>
        /// <param name="extraScopesToConsent">Scopes that you can request the end user to consent upfront, in addition to the scopes for the protected Web API
        /// for which you want to acquire a security token.</param>
        /// <param name="authority">Specific authority for which the token is requested. Passing a different value than configured does not change the configured value</param>
        /// <returns>Authentication result containing a token for the requested scopes and account</returns>
        public async Task <AuthenticationResult> AcquireTokenAsync(IEnumerable <string> scopes, IAccount account,
                                                                   UIBehavior behavior, string extraQueryParameters, IEnumerable <string> extraScopesToConsent, string authority)
        {
            GuardNetCore();
            GuardUIParentAndroid();

            Authority authorityInstance = Instance.Authority.CreateAuthority(ServiceBundle, authority, ValidateAuthority);

            return
                (await
                 AcquireTokenForUserCommonAsync(authorityInstance, scopes, extraScopesToConsent, account,
                                                behavior, extraQueryParameters, null, ApiEvent.ApiIds.AcquireTokenWithScopeUserBehaviorAuthority).ConfigureAwait(false));
        }
示例#2
0
        /// <summary>
        /// Interactive request to acquire token for a login with control of the UI behavior and possiblity of passing extra query parameters like additional claims
        /// </summary>
        /// <param name="scopes">Scopes requested to access a protected API</param>
        /// <param name="loginHint">Identifier of the user. Generally in UserPrincipalName (UPN) format, e.g. <c>[email protected]</c></param>
        /// <param name="behavior">Designed interactive experience for the user.</param>
        /// <param name="extraQueryParameters">This parameter will be appended as is to the query string in the HTTP authentication request to the authority.
        /// This is expected to be a string of segments of the form <c>key=value</c> separated by an ampersand character.
        /// The parameter can be null.</param>
        /// <returns>Authentication result containing a token for the requested scopes and account</returns>
        public async Task <AuthenticationResult> AcquireTokenAsync(IEnumerable <string> scopes, string loginHint,
                                                                   UIBehavior behavior, string extraQueryParameters)
        {
            GuardNetCore();
            GuardUIParentAndroid();

            Authority authority = Instance.Authority.CreateAuthority(ServiceBundle, Authority, ValidateAuthority);

            return
                (await
                 AcquireTokenForLoginHintCommonAsync(authority, scopes, null, loginHint,
                                                     behavior, extraQueryParameters, null, ApiEvent.ApiIds.AcquireTokenWithScopeHintBehavior).ConfigureAwait(false));
        }
示例#3
0
        internal IWebUI CreateWebAuthenticationDialog(UIParent parent, UIBehavior behavior, RequestContext requestContext)
        {
            //create instance of UIParent and assign useCorporateNetwork to UIParent
            if (parent == null)
            {
                parent = new UIParent();
            }

#if WINRT || DESKTOP
            //hidden webview can be used in both WinRT and desktop applications.
            parent.UseHiddenBrowser = behavior.Equals(UIBehavior.Never);
#if WINRT
            parent.UseCorporateNetwork = UseCorporateNetwork;
#endif
#endif

            return(PlatformPlugin.WebUIFactory.CreateAuthenticationDialog(parent, requestContext));
        }
示例#4
0
        internal IWebUI CreateWebAuthenticationDialog(UIParent parent, UIBehavior behavior, RequestContext requestContext)
        {
            //create instance of UIParent and assign useCorporateNetwork to UIParent
            if (parent == null)
            {
#pragma warning disable CS0618 // Throws a good exception on Android, but ctor cannot be removed for backwards compat reasons
                parent = new UIParent();
#pragma warning restore CS0618 // Type or member is obsolete
            }

#if WINDOWS_APP || DESKTOP
            //hidden webview can be used in both WinRT and desktop applications.
            parent.UseHiddenBrowser = behavior.Equals(UIBehavior.Never);
#if WINDOWS_APP
            parent.UseCorporateNetwork = UseCorporateNetwork;
#endif
#endif

            return(ServiceBundle.PlatformProxy.GetWebUiFactory().CreateAuthenticationDialog(parent.CoreUIParent, requestContext));
        }
示例#5
0
        private async Task <AuthenticationResult> AcquireTokenAsync(IEnumerable <string> scopes, IAccount account,
                                                                    UIBehavior behavior, string extraQueryParameters, IEnumerable <string> extraScopesToConsent, string authority, UIParent parent,
                                                                    string userName, string password, bool cacheResult)
        {
            Authority authorityInstance = Instance.Authority.CreateAuthority(ServiceBundle, authority, ValidateAuthority);

            var requestParams = CreateRequestParameters(authorityInstance, scopes, account, cacheResult ? UserTokenCache : null);

            requestParams.ExtraQueryParameters = extraQueryParameters;

            var handler = new NonInteractiveLoginRequest(
                ServiceBundle,
                requestParams,
                ApiEvent.ApiIds.AcquireTokenWithScopeUserBehaviorAuthority,
                extraScopesToConsent,
                behavior,
                CreateWebAuthenticationDialog(parent, behavior, requestParams.RequestContext),
                userName,
                password);

            return(await handler.RunAsync(CancellationToken.None).ConfigureAwait(false));
        }
示例#6
0
        private async Task <AuthenticationResult> AcquireTokenForUserCommonAsync(Authority authority, IEnumerable <string> scopes,
                                                                                 IEnumerable <string> extraScopesToConsent, IAccount user, UIBehavior behavior, string extraQueryParameters, UIParent parent, ApiEvent.ApiIds apiId)
        {
            var requestParams = CreateRequestParameters(authority, scopes, user, UserTokenCache);

            requestParams.ExtraQueryParameters = extraQueryParameters;

            var handler = new InteractiveRequest(
                ServiceBundle,
                requestParams,
                apiId,
                extraScopesToConsent,
                behavior,
                CreateWebAuthenticationDialog(parent, behavior, requestParams.RequestContext));

            return(await handler.RunAsync(CancellationToken.None).ConfigureAwait(false));
        }
示例#7
0
 /// <summary>
 /// Interactive request to acquire token for a given account, with the possibility of controlling the user experience, passing extra query
 /// parameters, providing extra scopes that the user can pre-consent to, and overriding the authority pre-configured in the application
 /// </summary>
 /// <param name="scopes">Scopes requested to access a protected API</param>
 /// <param name="account">Account to use for the interactive token acquisition. See <see cref="IAccount"/> for ways to get an account</param>
 /// <param name="behavior">Designed interactive experience for the user.</param>
 /// <param name="extraQueryParameters">This parameter will be appended as is to the query string in the HTTP authentication request to the authority.
 /// This is expected to be a string of segments of the form <c>key=value</c> separated by an ampersand character.
 /// The parameter can be null.</param>
 /// <param name="extraScopesToConsent">scopes that you can request the end user to consent upfront, in addition to the scopes for the protected Web API
 /// for which you want to acquire a security token.</param>
 /// <param name="authority">Specific authority for which the token is requested. Passing a different value than configured does not change the configured value</param>
 /// <param name="parent">Object containing a reference to the parent window/activity. REQUIRED for Xamarin.Android only.</param>
 /// <returns>Authentication result containing a token for the requested scopes and account</returns>
 public Task<AuthenticationResult> AcquireTokenAsync(IEnumerable<string> scopes, IAccount account,
 UIBehavior behavior, string extraQueryParameters, IEnumerable<string> extraScopesToConsent, string authority, UIParent parent)
 {
     throw new NotImplementedException();
 }
示例#8
0
 /// <summary>
 /// Interactive request to acquire token for a login with control of the UI behavior and possiblity of passing extra query parameters like additional claims
 /// </summary>
 /// <param name="scopes">Scopes requested to access a protected API</param>
 /// <param name="loginHint">Identifier of the user. Generally in UserPrincipalName (UPN) format, e.g. <c>[email protected]</c></param>
 /// <param name="behavior">Designed interactive experience for the user.</param>
 /// <param name="extraQueryParameters">This parameter will be appended as is to the query string in the HTTP authentication request to the authority.
 /// This is expected to be a string of segments of the form <c>key=value</c> separated by an ampersand character.
 /// The parameter can be null.</param>
 /// <param name="parent">Object containing a reference to the parent window/activity. REQUIRED for Xamarin.Android only.</param>
 /// <returns>Authentication result containing a token for the requested scopes and account</returns>
 public Task<AuthenticationResult> AcquireTokenAsync(IEnumerable<string> scopes, string loginHint,
     UIBehavior behavior, string extraQueryParameters, UIParent parent)
 {
     throw new NotImplementedException();
 }
示例#9
0
        private async Task <AuthenticationResult> AcquireTokenForLoginHintCommonAsync(Authority authority, IEnumerable <string> scopes,
                                                                                      IEnumerable <string> extraScopesToConsent, string loginHint, UIBehavior behavior,
                                                                                      string extraQueryParameters, UIParent parent, ApiEvent.ApiIds apiId)
        {
            var requestParams = CreateRequestParameters(authority, scopes, null, UserTokenCache);

            requestParams.ExtraQueryParameters = extraQueryParameters;
            var handler =
                new InteractiveRequest(requestParams, extraScopesToConsent, loginHint, behavior,
                                       CreateWebAuthenticationDialog(parent, behavior, requestParams.RequestContext))
            {
                ApiId = apiId
            };

            return(await handler.RunAsync().ConfigureAwait(false));
        }