Esempio n. 1
0
        protected override Task ApplyResponseChallengeAsync()
        {
            if (Response.StatusCode != 401)
            {
                return(Task.FromResult <object>(null));
            }

            var challenge = Helper.LookupChallenge(Options.AuthenticationType, Options.AuthenticationMode);

            if (challenge == null)
            {
                return(Task.FromResult <object>(null));
            }
            var baseUri =
                Request.Scheme +
                Uri.SchemeDelimiter +
                this.GetHostName() +
                Request.PathBase;

            var currentUri =
                baseUri +
                Request.Path +
                Request.QueryString;

            var redirectUri =
                baseUri +
                Options.CallbackPath;

            var properties = challenge.Properties;

            if (string.IsNullOrEmpty(properties.RedirectUri))
            {
                properties.RedirectUri = currentUri;
            }

            // OAuth2 10.12 CSRF
            GenerateCorrelationId(properties);

            // comma separated
            var scope = string.Join(",", Options.Scope);

            // allow scopes to be specified via the authentication properties for this request, when specified they will already be comma separated
            if (properties.Dictionary.ContainsKey("scope"))
            {
                scope = properties.Dictionary["scope"];
            }

            var state = Options.StateDataFormat.Protect(properties);

            var authorizationEndpoint =
                "https://www.linkedin.com/uas/oauth2/authorization" +
                "?response_type=code" +
                "&client_id=" + Uri.EscapeDataString(Options.ClientId) +
                "&redirect_uri=" + Uri.EscapeDataString(redirectUri) +
                "&scope=" + Uri.EscapeDataString(scope) +
                "&state=" + Uri.EscapeDataString(state);


            var redirectContext = new LinkedInApplyRedirectContext(
                Context, Options,
                properties, authorizationEndpoint);

            Options.Provider.ApplyRedirect(redirectContext);

            return(Task.FromResult <object>(null));
        }
 /// <summary>
 /// Called when a Challenge causes a redirect to authorize endpoint in the LinkedIn middleware
 /// </summary>
 /// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
 public virtual void ApplyRedirect(LinkedInApplyRedirectContext context)
 {
     OnApplyRedirect(context);
 }