Beispiel #1
0
        /// <summary>
        /// Gives new access token. Use this method for login or refreshing access token
        /// </summary>
        public static void LogOn()
        {
            QueryParameters qp = new QueryParameters();

            if (!string.IsNullOrEmpty(Connection.RefreshToken))
            {
                qp.Add("refresh_token", Connection.RefreshToken);
                GrantType = "refresh_token";
            }
            else
            {
                qp.Add("code", Code);
                GrantType = "authorization_code";
            }
            qp.Add("grant_type", GrantType);
            qp.Add("client_id", ClientId);
            qp.Add("client_secret", ClientSecret);
            qp.Add("redirect_uri", RedirectUri.ToString());
            try
            {
                connection = Requester.Request <Connection>(new RequestObject {
                    Url = UrlBuilder1.Concat(new Uri(UrlToken), qp)
                }).ElementAt(0);
            }
            catch
            {
                throw;
            }
        }
            public override void ExecuteResult(ControllerContext context)
            {
                //Ensure the forms auth module doesn't do a redirect!
                context.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;

                var owinCtx = context.HttpContext.GetOwinContext();

                //First, see if a custom challenge result callback is specified for the provider
                // and use it instead of the default if one is supplied.
                var loginProvider = owinCtx.Authentication
                    .GetExternalAuthenticationTypes()
                    .FirstOrDefault(p => p.AuthenticationType == LoginProvider);
                if (loginProvider != null)
                {
                    var providerChallengeResult = loginProvider.GetSignInChallengeResult(owinCtx);
                    if (providerChallengeResult != null)
                    {
                        owinCtx.Authentication.Challenge(providerChallengeResult, LoginProvider);
                        return;
                    }
                }

                var properties = new AuthenticationProperties() { RedirectUri = RedirectUri.EnsureEndsWith('/') };
                if (UserId != null)
                {
                    properties.Dictionary[XsrfKey] = UserId;
                }
                owinCtx.Authentication.Challenge(properties, LoginProvider);
            }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="scopes">Scopes which you want to use</param>
        /// <param name="response_type">Access token, code, ...</param>
        /// <param name="isMobileApps">True when your app is mobile otherwise false</param>
        /// <returns>Returns Url for authorization</returns>
        public static Uri GetAuthorizationUrl(string[] scopes, string responseType, bool isMobileApps)
        {
            if (scopes == null)
            {
                throw new ArgumentNullException("scopes");
            }
            if (string.IsNullOrEmpty(responseType))
            {
                throw new ArgumentNullException("responseType");
            }
            QueryParameters qp  = new QueryParameters();
            string          ret = "";

            foreach (string s in scopes)
            {
                ret += s + ",";
            }
            if (ret.EndsWith(",", StringComparison.Ordinal))
            {
                ret = ret.Substring(0, ret.Length - 1);
            }
            qp.Add("scope", ret);
            qp.Add("response_type", responseType);
            if (isMobileApps)
            {
                qp.Add("display", "touch");
            }
            qp.Add("client_id", ClientId);
            qp.Add("client_secret", ClientSecret);
            qp.Add("redirect_uri", RedirectUri.ToString());
            return(UrlBuilder1.Concat(new Uri(UrlAuthorize), qp));
        }
        public Uri ToUri()
        {
            StringBuilder builder = new StringBuilder(SpotifyUrls.Authorize.ToString());

            builder.Append($"?client_id={ClientId}");
            builder.Append($"&response_type={ResponseTypeParam.ToString().ToLower(CultureInfo.InvariantCulture)}");
            builder.Append($"&redirect_uri={HttpUtility.UrlEncode(RedirectUri.ToString())}");
            if (!string.IsNullOrEmpty(State))
            {
                builder.Append($"&state={HttpUtility.UrlEncode(State)}");
            }
            if (Scope != null)
            {
                builder.Append($"&scope={HttpUtility.UrlEncode(string.Join(" ", Scope))}");
            }
            if (ShowDialog != null)
            {
                builder.Append($"&show_dialog={ShowDialog.Value}");
            }
            if (CodeChallenge != null)
            {
                builder.Append($"&code_challenge={CodeChallenge}");
            }
            if (CodeChallengeMethod != null)
            {
                builder.Append($"&code_challenge_method={CodeChallengeMethod}");
            }

            return(new Uri(builder.ToString()));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest request,
            [OrchestrationClient] IDurableOrchestrationClient entityClient,
            TraceWriter log)
        {
            var code             = request.Query["code"];
            var state            = request.Query["state"];
            var error            = request.Query["error"];
            var errorDescription = request.Query["error_description"];

            var clientId     = Environment.GetEnvironmentVariable("LinkedInClientId", EnvironmentVariableTarget.Process);
            var clientSecret = Environment.GetEnvironmentVariable("LinkedInClientSecret", EnvironmentVariableTarget.Process);

            var redirectUri = RedirectUri.Generate(request);

            var accessToken = await _proxy.AccessToken(code, redirectUri, clientId, clientSecret);

            var me = await _proxy.Me(accessToken.AccessToken);

            var userData = new UserData
            {
                PersonId    = me.PersonId,
                AccessToken = accessToken.AccessToken,
                Expires     = accessToken.Expires
            };

            var entityId = new EntityId(nameof(User), state);

            await entityClient.SignalEntityAsync(entityId, "", userData, "default");

            return(new OkObjectResult("Done - you can close ths window"));
        }
Beispiel #6
0
        /// <summary>
        ///     Returns true if MsalAuthParameters instances are equal
        /// </summary>
        /// <param name="other">Instance of MsalAuthParameters to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(MsalAuthParameters other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((ClientApplicationId == other.ClientApplicationId ||
                  ClientApplicationId != null && ClientApplicationId.Equals(other.ClientApplicationId)) &&
                 (ClientId == other.ClientId || ClientId != null && ClientId.Equals(other.ClientId)) &&
                 (Authority == other.Authority || Authority != null && Authority.Equals(other.Authority)) &&
                 (RedirectUri == other.RedirectUri || RedirectUri != null && RedirectUri.Equals(other.RedirectUri)) &&
                 (RequestedScopes == other.RequestedScopes ||
                  RequestedScopes != null && RequestedScopes.Equals(other.RequestedScopes)) &&
                 (Username == other.Username || Username != null && Username.Equals(other.Username)) &&
                 (Password == other.Password || Password != null && Password.Equals(other.Password)) &&
                 (TelemetryCorrelationId == other.TelemetryCorrelationId || TelemetryCorrelationId != null &&
                  TelemetryCorrelationId.Equals(other.TelemetryCorrelationId)) &&
                 (AuthorizationType == other.AuthorizationType ||
                  AuthorizationType != null && AuthorizationType.Equals(other.AuthorizationType)));
        }
Beispiel #7
0
        public void Validate()
        {
            Preconditions.NotNullOrWhitespace(ClientId.ToString(), nameof(ClientId));
            Preconditions.NotNullOrWhitespace(RedirectUri.ToString(), nameof(RedirectUri));

            if (State.IsSpecified)
            {
                Preconditions.NotNullOrWhitespace(State.ToString(), nameof(State));
            }
        }
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (ClientId != null ? ClientId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (RedirectUri != null ? RedirectUri.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Environment;
         hashCode = (hashCode * 397) ^ (int)RuntimePlatform;
         return(hashCode);
     }
 }
Beispiel #9
0
        /// <summary>
        ///     Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                int hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (ClientApplicationId != null)
                {
                    hashCode = hashCode * 59 + ClientApplicationId.GetHashCode();
                }

                if (ClientId != null)
                {
                    hashCode = hashCode * 59 + ClientId.GetHashCode();
                }

                if (Authority != null)
                {
                    hashCode = hashCode * 59 + Authority.GetHashCode();
                }

                if (RedirectUri != null)
                {
                    hashCode = hashCode * 59 + RedirectUri.GetHashCode();
                }

                if (RequestedScopes != null)
                {
                    hashCode = hashCode * 59 + RequestedScopes.GetHashCode();
                }

                if (Username != null)
                {
                    hashCode = hashCode * 59 + Username.GetHashCode();
                }

                if (Password != null)
                {
                    hashCode = hashCode * 59 + Password.GetHashCode();
                }

                if (TelemetryCorrelationId != null)
                {
                    hashCode = hashCode * 59 + TelemetryCorrelationId.GetHashCode();
                }

                if (AuthorizationType != null)
                {
                    hashCode = hashCode * 59 + AuthorizationType.GetHashCode();
                }

                return(hashCode);
            }
        }
        public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest request, TraceWriter log)
        {
            var clientId    = Environment.GetEnvironmentVariable("LinkedInClientId", EnvironmentVariableTarget.Process);
            var state       = request.Query["userid"];
            var redirectUri = RedirectUri.Generate(request);
            var redirectTo  = $"{LINKEDIN_URL}?response_type=code&client_id={clientId}&state={state}&scope=r_liteprofile w_member_social&redirect_uri={redirectUri}";

            var response = new RedirectResult(redirectTo);

            return(response);
        }
Beispiel #11
0
        public Uri ToUri()
        {
            var builder = new StringBuilder(AuthorizeUrl);

            builder.Append($"?client_id={ClientId}");
            builder.Append($"&redirect_uri={HttpUtility.UrlEncode(RedirectUri.ToString())}");
            builder.Append($"&scope=me");
            builder.Append($"&state=available");
            builder.Append($"&response_type=code");

            return(new Uri(builder.ToString()));
        }
        public override int GetHashCode()
        {
            int hashCode = -994318680;

            if (ClientId != null)
            {
                hashCode += ClientId.GetHashCode();
            }

            if (ClientSecret != null)
            {
                hashCode += ClientSecret.GetHashCode();
            }

            if (Code != null)
            {
                hashCode += Code.GetHashCode();
            }

            if (RedirectUri != null)
            {
                hashCode += RedirectUri.GetHashCode();
            }

            if (GrantType != null)
            {
                hashCode += GrantType.GetHashCode();
            }

            if (RefreshToken != null)
            {
                hashCode += RefreshToken.GetHashCode();
            }

            if (MigrationToken != null)
            {
                hashCode += MigrationToken.GetHashCode();
            }

            if (Scopes != null)
            {
                hashCode += Scopes.GetHashCode();
            }

            if (ShortLived != null)
            {
                hashCode += ShortLived.GetHashCode();
            }

            return(hashCode);
        }
Beispiel #13
0
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew">是否插入</param>
        public override void Valid(Boolean isNew)
        {
            // 如果没有脏数据,则不需要进行任何处理
            if (!HasDirty)
            {
                return;
            }

            // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
            if (RedirectUri.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(RedirectUri), "RedirectUri不能为空!");
            }

            // 在新插入数据或者修改了指定字段时进行修正
        }
Beispiel #14
0
        /// <summary>
        /// Initialisiert das Formular
        /// </summary>
        /// <param name="context">Der Kontext, indem das Steuerelement dargestellt wird</param>
        public virtual void Initialize(RenderContext context)
        {
            var renderContext = new RenderContextFormular(context, this);

            Scope = ParameterScope.Local;
            Name  = "Form";

            SubmitButton.Click += (s, e) =>
            {
                Validate();

                if (Valid)
                {
                    OnProcess();

                    if (!string.IsNullOrWhiteSpace(RedirectUri?.ToString()))
                    {
                        context.Page.Redirecting(RedirectUri);
                    }
                }
            };
        }
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is ObtainTokenRequest other &&
                   ((ClientId == null && other.ClientId == null) || (ClientId?.Equals(other.ClientId) == true)) &&
                   ((ClientSecret == null && other.ClientSecret == null) || (ClientSecret?.Equals(other.ClientSecret) == true)) &&
                   ((Code == null && other.Code == null) || (Code?.Equals(other.Code) == true)) &&
                   ((RedirectUri == null && other.RedirectUri == null) || (RedirectUri?.Equals(other.RedirectUri) == true)) &&
                   ((GrantType == null && other.GrantType == null) || (GrantType?.Equals(other.GrantType) == true)) &&
                   ((RefreshToken == null && other.RefreshToken == null) || (RefreshToken?.Equals(other.RefreshToken) == true)) &&
                   ((MigrationToken == null && other.MigrationToken == null) || (MigrationToken?.Equals(other.MigrationToken) == true)) &&
                   ((Scopes == null && other.Scopes == null) || (Scopes?.Equals(other.Scopes) == true)) &&
                   ((ShortLived == null && other.ShortLived == null) || (ShortLived?.Equals(other.ShortLived) == true)));
        }
Beispiel #16
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (DataCustodianId != null)
         {
             hashCode = hashCode * 59 + DataCustodianId.GetHashCode();
         }
         if (DataCustodianApplicationStatus != null)
         {
             hashCode = hashCode * 59 + DataCustodianApplicationStatus.GetHashCode();
         }
         if (ThirdPartyApplicationDescription != null)
         {
             hashCode = hashCode * 59 + ThirdPartyApplicationDescription.GetHashCode();
         }
         if (ThirdPartyApplicationStatus != null)
         {
             hashCode = hashCode * 59 + ThirdPartyApplicationStatus.GetHashCode();
         }
         if (ThirdPartyApplicationType != null)
         {
             hashCode = hashCode * 59 + ThirdPartyApplicationType.GetHashCode();
         }
         if (ThirdPartyApplicationUse != null)
         {
             hashCode = hashCode * 59 + ThirdPartyApplicationUse.GetHashCode();
         }
         if (ThirdPartyPhone != null)
         {
             hashCode = hashCode * 59 + ThirdPartyPhone.GetHashCode();
         }
         if (AuthorizationServerUri != null)
         {
             hashCode = hashCode * 59 + AuthorizationServerUri.GetHashCode();
         }
         if (ThirdPartyNotifyUri != null)
         {
             hashCode = hashCode * 59 + ThirdPartyNotifyUri.GetHashCode();
         }
         if (AuthorizationServerAuthorizationEndpoint != null)
         {
             hashCode = hashCode * 59 + AuthorizationServerAuthorizationEndpoint.GetHashCode();
         }
         if (AuthorizationServerRegistrationEndpoint != null)
         {
             hashCode = hashCode * 59 + AuthorizationServerRegistrationEndpoint.GetHashCode();
         }
         if (AuthorizationServerTokenEndpoint != null)
         {
             hashCode = hashCode * 59 + AuthorizationServerTokenEndpoint.GetHashCode();
         }
         if (DataCustodianBulkRequestURI != null)
         {
             hashCode = hashCode * 59 + DataCustodianBulkRequestURI.GetHashCode();
         }
         if (DataCustodianResourceEndpoint != null)
         {
             hashCode = hashCode * 59 + DataCustodianResourceEndpoint.GetHashCode();
         }
         if (ThirdPartyScopeSelectionURI != null)
         {
             hashCode = hashCode * 59 + ThirdPartyScopeSelectionURI.GetHashCode();
         }
         if (ThirdPartyUserPortalScreenURI != null)
         {
             hashCode = hashCode * 59 + ThirdPartyUserPortalScreenURI.GetHashCode();
         }
         if (ClientSecret != null)
         {
             hashCode = hashCode * 59 + ClientSecret.GetHashCode();
         }
         if (LogoUri != null)
         {
             hashCode = hashCode * 59 + LogoUri.GetHashCode();
         }
         if (ClientName != null)
         {
             hashCode = hashCode * 59 + ClientName.GetHashCode();
         }
         if (ClientUri != null)
         {
             hashCode = hashCode * 59 + ClientUri.GetHashCode();
         }
         if (RedirectUri != null)
         {
             hashCode = hashCode * 59 + RedirectUri.GetHashCode();
         }
         if (ClientId != null)
         {
             hashCode = hashCode * 59 + ClientId.GetHashCode();
         }
         if (TosUri != null)
         {
             hashCode = hashCode * 59 + TosUri.GetHashCode();
         }
         if (PolicyUri != null)
         {
             hashCode = hashCode * 59 + PolicyUri.GetHashCode();
         }
         if (SoftwareId != null)
         {
             hashCode = hashCode * 59 + SoftwareId.GetHashCode();
         }
         if (SoftwareVersion != null)
         {
             hashCode = hashCode * 59 + SoftwareVersion.GetHashCode();
         }
         if (ClientIdIssuedAt != null)
         {
             hashCode = hashCode * 59 + ClientIdIssuedAt.GetHashCode();
         }
         if (ClientSecretExpiresAt != null)
         {
             hashCode = hashCode * 59 + ClientSecretExpiresAt.GetHashCode();
         }
         if (Contacts != null)
         {
             hashCode = hashCode * 59 + Contacts.GetHashCode();
         }
         if (TokenEndpointAuthMethod != null)
         {
             hashCode = hashCode * 59 + TokenEndpointAuthMethod.GetHashCode();
         }
         if (Scope != null)
         {
             hashCode = hashCode * 59 + Scope.GetHashCode();
         }
         if (GrantTypes != null)
         {
             hashCode = hashCode * 59 + GrantTypes.GetHashCode();
         }
         if (ResponseTypes != null)
         {
             hashCode = hashCode * 59 + ResponseTypes.GetHashCode();
         }
         if (RegistrationClientUri != null)
         {
             hashCode = hashCode * 59 + RegistrationClientUri.GetHashCode();
         }
         if (RegistrationAccessToken != null)
         {
             hashCode = hashCode * 59 + RegistrationAccessToken.GetHashCode();
         }
         if (DataCustodianScopeSelectionScreenURI != null)
         {
             hashCode = hashCode * 59 + DataCustodianScopeSelectionScreenURI.GetHashCode();
         }
         return(hashCode);
     }
 }
Beispiel #17
0
        /// <summary>
        /// Returns true if ApplicationInformation instances are equal
        /// </summary>
        /// <param name="other">Instance of ApplicationInformation to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ApplicationInformation other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     DataCustodianId == other.DataCustodianId ||
                     DataCustodianId != null &&
                     DataCustodianId.Equals(other.DataCustodianId)
                     ) &&
                 (
                     DataCustodianApplicationStatus == other.DataCustodianApplicationStatus ||
                     DataCustodianApplicationStatus != null &&
                     DataCustodianApplicationStatus.Equals(other.DataCustodianApplicationStatus)
                 ) &&
                 (
                     ThirdPartyApplicationDescription == other.ThirdPartyApplicationDescription ||
                     ThirdPartyApplicationDescription != null &&
                     ThirdPartyApplicationDescription.Equals(other.ThirdPartyApplicationDescription)
                 ) &&
                 (
                     ThirdPartyApplicationStatus == other.ThirdPartyApplicationStatus ||
                     ThirdPartyApplicationStatus != null &&
                     ThirdPartyApplicationStatus.Equals(other.ThirdPartyApplicationStatus)
                 ) &&
                 (
                     ThirdPartyApplicationType == other.ThirdPartyApplicationType ||
                     ThirdPartyApplicationType != null &&
                     ThirdPartyApplicationType.Equals(other.ThirdPartyApplicationType)
                 ) &&
                 (
                     ThirdPartyApplicationUse == other.ThirdPartyApplicationUse ||
                     ThirdPartyApplicationUse != null &&
                     ThirdPartyApplicationUse.Equals(other.ThirdPartyApplicationUse)
                 ) &&
                 (
                     ThirdPartyPhone == other.ThirdPartyPhone ||
                     ThirdPartyPhone != null &&
                     ThirdPartyPhone.Equals(other.ThirdPartyPhone)
                 ) &&
                 (
                     AuthorizationServerUri == other.AuthorizationServerUri ||
                     AuthorizationServerUri != null &&
                     AuthorizationServerUri.Equals(other.AuthorizationServerUri)
                 ) &&
                 (
                     ThirdPartyNotifyUri == other.ThirdPartyNotifyUri ||
                     ThirdPartyNotifyUri != null &&
                     ThirdPartyNotifyUri.Equals(other.ThirdPartyNotifyUri)
                 ) &&
                 (
                     AuthorizationServerAuthorizationEndpoint == other.AuthorizationServerAuthorizationEndpoint ||
                     AuthorizationServerAuthorizationEndpoint != null &&
                     AuthorizationServerAuthorizationEndpoint.Equals(other.AuthorizationServerAuthorizationEndpoint)
                 ) &&
                 (
                     AuthorizationServerRegistrationEndpoint == other.AuthorizationServerRegistrationEndpoint ||
                     AuthorizationServerRegistrationEndpoint != null &&
                     AuthorizationServerRegistrationEndpoint.Equals(other.AuthorizationServerRegistrationEndpoint)
                 ) &&
                 (
                     AuthorizationServerTokenEndpoint == other.AuthorizationServerTokenEndpoint ||
                     AuthorizationServerTokenEndpoint != null &&
                     AuthorizationServerTokenEndpoint.Equals(other.AuthorizationServerTokenEndpoint)
                 ) &&
                 (
                     DataCustodianBulkRequestURI == other.DataCustodianBulkRequestURI ||
                     DataCustodianBulkRequestURI != null &&
                     DataCustodianBulkRequestURI.Equals(other.DataCustodianBulkRequestURI)
                 ) &&
                 (
                     DataCustodianResourceEndpoint == other.DataCustodianResourceEndpoint ||
                     DataCustodianResourceEndpoint != null &&
                     DataCustodianResourceEndpoint.Equals(other.DataCustodianResourceEndpoint)
                 ) &&
                 (
                     ThirdPartyScopeSelectionURI == other.ThirdPartyScopeSelectionURI ||
                     ThirdPartyScopeSelectionURI != null &&
                     ThirdPartyScopeSelectionURI.Equals(other.ThirdPartyScopeSelectionURI)
                 ) &&
                 (
                     ThirdPartyUserPortalScreenURI == other.ThirdPartyUserPortalScreenURI ||
                     ThirdPartyUserPortalScreenURI != null &&
                     ThirdPartyUserPortalScreenURI.Equals(other.ThirdPartyUserPortalScreenURI)
                 ) &&
                 (
                     ClientSecret == other.ClientSecret ||
                     ClientSecret != null &&
                     ClientSecret.Equals(other.ClientSecret)
                 ) &&
                 (
                     LogoUri == other.LogoUri ||
                     LogoUri != null &&
                     LogoUri.Equals(other.LogoUri)
                 ) &&
                 (
                     ClientName == other.ClientName ||
                     ClientName != null &&
                     ClientName.Equals(other.ClientName)
                 ) &&
                 (
                     ClientUri == other.ClientUri ||
                     ClientUri != null &&
                     ClientUri.Equals(other.ClientUri)
                 ) &&
                 (
                     RedirectUri == other.RedirectUri ||
                     RedirectUri != null &&
                     RedirectUri.SequenceEqual(other.RedirectUri)
                 ) &&
                 (
                     ClientId == other.ClientId ||
                     ClientId != null &&
                     ClientId.Equals(other.ClientId)
                 ) &&
                 (
                     TosUri == other.TosUri ||
                     TosUri != null &&
                     TosUri.Equals(other.TosUri)
                 ) &&
                 (
                     PolicyUri == other.PolicyUri ||
                     PolicyUri != null &&
                     PolicyUri.Equals(other.PolicyUri)
                 ) &&
                 (
                     SoftwareId == other.SoftwareId ||
                     SoftwareId != null &&
                     SoftwareId.Equals(other.SoftwareId)
                 ) &&
                 (
                     SoftwareVersion == other.SoftwareVersion ||
                     SoftwareVersion != null &&
                     SoftwareVersion.Equals(other.SoftwareVersion)
                 ) &&
                 (
                     ClientIdIssuedAt == other.ClientIdIssuedAt ||
                     ClientIdIssuedAt != null &&
                     ClientIdIssuedAt.Equals(other.ClientIdIssuedAt)
                 ) &&
                 (
                     ClientSecretExpiresAt == other.ClientSecretExpiresAt ||
                     ClientSecretExpiresAt != null &&
                     ClientSecretExpiresAt.Equals(other.ClientSecretExpiresAt)
                 ) &&
                 (
                     Contacts == other.Contacts ||
                     Contacts != null &&
                     Contacts.SequenceEqual(other.Contacts)
                 ) &&
                 (
                     TokenEndpointAuthMethod == other.TokenEndpointAuthMethod ||
                     TokenEndpointAuthMethod != null &&
                     TokenEndpointAuthMethod.Equals(other.TokenEndpointAuthMethod)
                 ) &&
                 (
                     Scope == other.Scope ||
                     Scope != null &&
                     Scope.SequenceEqual(other.Scope)
                 ) &&
                 (
                     GrantTypes == other.GrantTypes ||
                     GrantTypes != null &&
                     GrantTypes.SequenceEqual(other.GrantTypes)
                 ) &&
                 (
                     ResponseTypes == other.ResponseTypes ||
                     ResponseTypes != null &&
                     ResponseTypes.Equals(other.ResponseTypes)
                 ) &&
                 (
                     RegistrationClientUri == other.RegistrationClientUri ||
                     RegistrationClientUri != null &&
                     RegistrationClientUri.Equals(other.RegistrationClientUri)
                 ) &&
                 (
                     RegistrationAccessToken == other.RegistrationAccessToken ||
                     RegistrationAccessToken != null &&
                     RegistrationAccessToken.Equals(other.RegistrationAccessToken)
                 ) &&
                 (
                     DataCustodianScopeSelectionScreenURI == other.DataCustodianScopeSelectionScreenURI ||
                     DataCustodianScopeSelectionScreenURI != null &&
                     DataCustodianScopeSelectionScreenURI.Equals(other.DataCustodianScopeSelectionScreenURI)
                 ));
        }
Beispiel #18
0
        private void OnNavigated(object sender, WebBrowserNavigatedEventArgs args)
        {
            try
            {
                // Ignore the navigated event after we have an access token
                if (!string.IsNullOrEmpty(AccessToken))
                {
                    return;
                }

                // Check for errors
                if (args.Url.Fragment.StartsWith("#/error?"))
                {
                    // Strip leading part of path and parse
                    var errorFragment = HttpUtility.ParseQueryString(args.Url.Fragment.Substring(8));

                    // Check for errorKey parameter
                    if (errorFragment.AllKeys.Contains("errorKey"))
                    {
                        RaiseExceptionEncountered("OAuthWebBrowser.Navigated", new Exception(errorFragment["errorKey"]));
                        return;
                    }
                }

                // Scope error
                if (args.Url.Fragment.StartsWith("#error"))
                {
                    // Strip leading part of path and parse
                    var errorFragment = HttpUtility.ParseQueryString(args.Url.Fragment.Substring(1));

                    RaiseExceptionEncountered("OAuthWebBrowser.Navigated", new Exception($"Error: {errorFragment["error"]}, {errorFragment["error_description"]}"));

                    return;
                }

                // Process our redirect URL
                if (args.Url.ToString().ToLowerInvariant().StartsWith(RedirectUri.ToLowerInvariant()))
                {
                    var queryString = HttpUtility.ParseQueryString(args.Url.Query);

                    var fragment = HttpUtility.ParseQueryString(args.Url.Fragment.TrimStart('#'));
                    // Get the token from the redirect URI (implicit grant)
                    if (fragment.AllKeys.Contains("expires_in"))
                    {
                        var i = 0;
                        if (int.TryParse(fragment["expires_in"], out i))
                        {
                            TokenExpiresInSeconds = i;
                        }
                    }
                    if (fragment.AllKeys.Contains("access_token"))
                    {
                        AccessToken = fragment["access_token"];
                        if (RedirectUriIsFake)
                        {
                            Visible = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                RaiseExceptionEncountered("OAuthWebBrowser.OnNavigated", ex);
            }
        }
 public string CreateUri()
 {
     return($"https://accounts.spotify.com/en/authorize/?client_id={ClientId}&response_type=code&redirect_uri={RedirectUri.Replace("/", "%2F")}&state={State}&scope={ScopeUri}&show_dialog={ShowDialog}");
 }
        private async Task <OAuth2Response> HandleJSRedirect()
        {
            var context = await http.GetContextAsync();

            // We only care about request to TokenRedirectUri endpoint.
            while (context.Request.Url.AbsolutePath != JSRedirectUri.AbsolutePath)
            {
                context = await http.GetContextAsync();
            }

            String redirectUri = new Uri(context.Request.QueryString["url_with_fragment"]).ToString();

            //retrieve code from redirectUri
            int            index    = redirectUri.IndexOf("code=");
            String         code     = redirectUri.Substring(index + 5);
            OAuth2Response response = await DropboxOAuth2Helper.ProcessCodeFlowAsync(code, _appKey, _appSecret, RedirectUri.ToString());

            return(response);
        }