/// <summary> /// Indicates that the service should be bound to the specified callback method. /// </summary> /// <typeparam name="TImplementation">The type of the implementation.</typeparam> /// <param name="method">The method.</param> /// <returns>The fluent syntax.</returns> protected IBindingWhenInNamedWithOrOnSyntax <TImplementation> InternalToMethod <TImplementation>(Func <IContext, TImplementation> method) { var callbackProvider = new CallbackProvider <TImplementation>(method); this.BindingConfiguration.ProviderCallback = ctx => callbackProvider; this.BindingConfiguration.Target = BindingTarget.Method; return(new BindingConfigurationBuilder <TImplementation>(this.BindingConfiguration, this.ServiceNames)); }
public void ProviderInvokesCallbackToRetrieveValue() { var sword = new Sword(); provider = new CallbackProvider<Sword>(c => sword); var result = provider.Create(contextMock.Object); result.Should().BeSameAs(sword); }
public void ProviderInvokesCallbackToRetrieveValue() { var sword = new Sword(); provider = new CallbackProvider <Sword>(c => sword); var result = provider.Create(contextMock.Object); result.Should().BeSameAs(sword); }
public ActionResult AuthenticateCallback(string providerkey) { if (string.IsNullOrEmpty(providerkey)) { throw new ArgumentException("No provider key was supplied on the callback."); } // Determine which settings we need, based on the Provider. var settings = AuthenticationService.GetAuthenticateServiceSettings(providerkey, Request.Url, Url.CallbackFromOAuthProvider()); // Pull the "ToKeep" token from the cookie and the "ToSend" token from the query string var keptToken = DeserializeToken(Request); var recievedToken = Request.QueryString["state"]; if (string.IsNullOrEmpty(recievedToken)) { throw new InvalidOperationException( "No state/recievedToken was retrieved from the provider. Are you sure you passed any state/token data to provider .. and .. that the provider can send it back to us? We need this to prevent any Cross site request forgery."); } // Validate the token against the recieved one and grab extra data string extraData = _antiForgery.ValidateToken(keptToken, recievedToken); var model = new AuthenticateCallbackData(); try { // Grab the authenticated client information. model.AuthenticatedClient = AuthenticationService.GetAuthenticatedClient(settings, Request.QueryString); } catch (Exception exception) { model.Exception = exception; } // If we have a redirect Url, lets grab this :) // NOTE: We've implimented the extraData part of the tokenData as the redirect url. if (!string.IsNullOrEmpty(extraData)) { model.RedirectUrl = new Uri(extraData); } // Finally! We can hand over the logic to the consumer to do whatever they want. return(CallbackProvider.Process(HttpContext, model)); }