public async Task <BoolValue <string[]> > TeyGetUserInfoTypes()
        {
            if (AccessToken is null)
            {
                _log?.Warning("Cannot get user information without a valid access token");
                return(BoolValue <string[]> .Fail());
            }

            try
            {
                if (_userInformation is { })
                {
                    return(BoolValue <string[]> .Success(_userInformation.Types));
                }

                var discoDoc = DiscoveryDocument.Current;
                if (discoDoc is null)
                {
                    var gotDiscoDoc = await DiscoveryDocument.TryDownloadAndSetCurrent(this, true);

                    if (!gotDiscoDoc)
                    {
                        _log?.Debug("ERROR: Failed to retrieve the discovery document. Cannot resolve user information endpoint");
                        return(BoolValue <string[]> .Fail("Failed to retrieve the discovery document. Cannot resolve user information endpoint"));
                    }
                    discoDoc = gotDiscoDoc.Value;
                }
                _userInfoLoader ??= new UserInfoLoader(AccessToken, discoDoc, _log);
                _userInformation = await _userInfoLoader.AwaitDownloadedAsync();

                return(BoolValue <string[]> .Success(_userInformation.Types));
            }
        /// <summary>
        ///   Attempts obtaining user information.
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// </remarks>
        public async Task <BoolValue <UserInformation> > TryGetUserInformationAsync()
        {
            _log?.Debug("[GET USER INFORMATION BEGIN]");

            if (AccessToken is null)
            {
                _log?.Warning("Cannot get user information without a valid access token");
                return(BoolValue <UserInformation> .Fail());
            }

            if (_userInformation != null)
            {
                _log?.Debug("User information was cached");
                return(BoolValue <UserInformation> .Success(_userInformation));
            }

            try
            {
                _log?.Debug("Retrieves user information from API ...");
                var discoDoc = DiscoveryDocument.Current;
                if (discoDoc is null)
                {
                    var gotDiscoDoc = await DiscoveryDocument.TryDownloadAndSetCurrent(this, true);

                    if (!gotDiscoDoc)
                    {
                        _log?.Debug("ERROR: Failed to retrieve the discovery document. Cannot resolve user information endpoint");
                        return(BoolValue <UserInformation> .Fail("Failed to retrieve the discovery document. Cannot resolve user information endpoint"));
                    }

                    discoDoc = gotDiscoDoc.Value;
                }

                _userInfoLoader ??= new UserInfoLoader(AccessToken, discoDoc, _log);
                _userInformation = await _userInfoLoader.AwaitDownloadedAsync();

                _log?.Debug("Successfully received user information from API");
                return(BoolValue <UserInformation> .Success(_userInformation));
            }
            catch (Exception ex)
            {
                const string Message = "Failed while retrieving user information from API";
                _log?.Error(ex, Message);
                return(BoolValue <UserInformation> .Fail(Message, ex));
            }
            finally
            {
                _log?.Debug("[GET USER INFORMATION END]");
            }
        }
Exemplo n.º 3
0
        static async void onAuthorized(object sender, AuthResultEventArgs args)
        {
            await DiscoveryDocument.TryDownloadAndSetCurrent(args.Result.Value, true);

            // obsolete AuthScope.Discover(discoDocumentDownloaded.Value);
        }