Exemplo n.º 1
0
        public void LoginAndEnrollAccount(string identity   = null,
                                          Endpoint endPoint = null,
                                          IAzureAuthenticatorService authenticator = null)
        {
            try
            {
                _requestedIdentity = identity;
                //set the endpoint
                if (endPoint != null)
                {
                    Endpoint = endPoint;
                }

                CacheToken token = AzureTokenCacheService.GetTokenByUpn(identity)[0];
                if (token != null)
                {
                    var tenantId = token.TenantId;
                    var aadId    = token.UserInfo?.UniqueId;
                    _enrollmentManager.RegisterAccountForMAM(identity, aadId, tenantId);
                    return;
                }
            }
            catch (Exception ex)
            {
                var status = new Status()
                {
                    Error      = ex.Message,
                    DidSucceed = false,
                    StatusCode = StatusCode.InternalError
                };

                _loggingService.LogError(typeof(EnrollmentService), ex, ex.Message);
                EnrollmentRequestStatus(status, _authenticationResult);
            }
        }
Exemplo n.º 2
0
        public string AcquireToken(string upn, string aadId, string resourceId)
        {
            var result      = string.Empty;
            var cacheTokens = AzureTokenCacheService.GetTokenByUpn(upn);

            foreach (var token in cacheTokens)
            {
                if (token.UserInfo?.UniqueId == aadId)
                {
                    return(token.Token);
                }
            }
            return(result);
        }
        public void LoginAndEnrollAccount(
            string identity   = null,
            Endpoint endPoint = null,
            IAzureAuthenticatorService authenticator = null)
        {
            try
            {
                if (endPoint != null)
                {
                    Endpoint = endPoint;
                }

                if (Endpoint != null)
                {
                    SetAdalInformation(endPoint);
                }

                CacheToken token = AzureTokenCacheService.GetTokenByUpn(identity).FirstOrDefault();
                if (token != null)
                {
                    InvokeOnMainThread(() =>
                    {
                        //TODO
                        //debugging - bug with getting tokens via register method
                        //working with @Kyle at Microsoft on issue.  Only work around
                        //is to run LoginAndEnroll instead

                        //IntuneMAMEnrollmentManager.Instance.LoginAndEnrollAccount(identity);

                        IntuneMAMEnrollmentManager.Instance.RegisterAndEnrollAccount(identity);
                    });
                }
                else
                {
                    IntuneMAMEnrollmentManager.Instance.LoginAndEnrollAccount(identity);
                }
            }
            catch (Exception ex)
            {
                _loggingService.LogError(typeof(EnrollmentService), ex, ex.Message);
            }
        }
Exemplo n.º 4
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request,
                                                                      CancellationToken cancellationToken)
        {
            try
            {
                var token = AzureTokenCacheService.GetTokenByEndpoint(_endpoint);

                //if old token exist - get rid of it
                if (request.Headers.Contains("Authorization"))
                {
                    request.Headers.Remove("Authorization");
                }

                request.Headers.Add("Authorization", $"Bearer {token.Token}");
            }
            catch (Exception ex)
            {
                _loggingService.LogError(typeof(CachedTokenHttpClientHandler), ex, ex.Message);
            }
            return(await base.SendAsync(request, cancellationToken).ConfigureAwait(false));
        }