Exemple #1
0
        /// <summary>
        /// Gets and loads instance endpoints
        /// </summary>
        /// <param name="ct">The token to monitor for cancellation requests</param>
        /// <returns>Instance endpoints</returns>
        public InstanceEndpoints GetEndpoints(CancellationToken ct = default)
        {
            lock (_endpoints_lock)
            {
                if (_endpoints == null)
                {
                    try
                    {
                        // Get and load API endpoints.
                        var endpoints   = new InstanceEndpoints();
                        var uri_builder = new UriBuilder(Base);
                        uri_builder.Path += "info.json";
                        endpoints.LoadJSON(Xml.Response.Get(
                                               uri: uri_builder.Uri,
                                               ct: ct).Value, ct);

                        // If we got here, save the endpoints.
                        _endpoints = endpoints;
                    }
                    catch (OperationCanceledException) { throw; }
                    catch (Exception ex) { throw new AggregateException(Resources.Strings.ErrorEndpointsLoad, ex); }
                }

                return(_endpoints);
            }
        }
Exemple #2
0
        /// <summary>
        /// Constructs the authenticating instance
        /// </summary>
        /// <param name="authorization_endpoint">Authorization endpoint URI - used by the client to obtain authorization from the resource owner via user-agent redirection.</param>
        /// <param name="token_endpoint">Token endpoint URI - used by the client to exchange an authorization grant for an access token, typically with client authentication.</param>
        public Instance(Uri authorization_endpoint, Uri token_endpoint) :
            this()
        {
            // Make a guess for the base name - required to identify instance (e.g. when caching access tokens).
            _base = new Uri(authorization_endpoint.GetLeftPart(UriPartial.Authority) + "/");

            // Set display name to authorization URI hostname.
            _display_name = authorization_endpoint.Host;

            // Set instance logo to /favicon.ico, perhaps we might get lucky.
            _logo = new UriBuilder(authorization_endpoint)
            {
                Path = "/favicon.ico"
            }.Uri;

            // Set API endpoints manually.
            _endpoints = new InstanceEndpoints()
            {
                AuthorizationEndpoint = authorization_endpoint,
                TokenEndpoint         = token_endpoint,
            };
        }