public OAuthClientModule(EntityArea area, OAuthClientSettings settings = null) : base(area, "OAuthClient", version: CurrentVersion) { Settings = settings ?? new OAuthClientSettings(); this.App.RegisterConfig(this.Settings); RegisterEntities(typeof(IOAuthRemoteServer), typeof(IOAuthRemoteServerAccount), typeof(IOAuthAccessToken), typeof(IOAuthClientFlow), typeof(IOAuthOpenIdToken), typeof(IOAuthExternalUser)); App.RegisterService <IOAuthClientService>(this); Requires <EncryptedData.EncryptedDataModule>(); }
public OAuthClientModule(EntityArea area, OAuthClientSettings settings = null) : base(area, "OAuthClient", version: CurrentVersion) { Settings = settings ?? new OAuthClientSettings(); this.App.RegisterConfig(this.Settings); RegisterEntities(typeof(IOAuthRemoteServer), typeof(IOAuthRemoteServerAccount), typeof(IOAuthAccessToken), typeof(IOAuthClientFlow), typeof(IOAuthOpenIdToken), typeof(IOAuthExternalUser)); App.RegisterService<IOAuthClientService>(this); Requires<EncryptedData.EncryptedDataModule>(); }
public OAuthEntityApp(string serviceUrl) : base() { var data = AddArea("data"); // Note: we have to specify redirect URL explicitly here; for real world apps the redirect URL may be left null - // it will be configured automatically by OAuthClientModule on first web api call // (see EntityApp.WebInitialize, OAuthClientModule.WebInitialize). But in this demo app the initialization will // happen only when the controller is hit (by redirect) - but we need to know redirect URL before that. // This is URL of RedirectController - it will handle redirects from remote OAuth server var oauthStt = new OAuthClientSettings(redirectUrl: serviceUrl + "/api/oauth_redirect", defaultAccountName: "TestAccount", redirectResponseText: "Authorization completed, please return to OAuthDemoApp."); //Note for redirectResponseText: alternatively you can specify after-redirect landing page (another redirect from RedirectController) var oauth = new OAuthClientModule(data, oauthStt); var dbInfo = new Modules.DbInfo.DbInfoModule(data); var encrData = new Modules.EncryptedData.EncryptedDataModule(data); this.ApiConfiguration.RegisterController(typeof(Vita.Modules.OAuthClient.Api.OAuthRedirectController)); }
// If RedirectURL is missing, derive it automatically - convenient for testing public static void AutoAssignRedirectUrl(OAuthClientSettings settings, OperationContext context) { if (!string.IsNullOrWhiteSpace(settings.RedirectUrl)) { return; } var webCtx = context.WebContext; //try to set redirect URL using current call's base URL and default path. First check we have web context. Util.Check(webCtx != null, "RedirectURL is not set in OAuthClientSettings; failed to derive it from current Web request - WebContext is missing."); // We are in web app; use current web context to derive this server URL. var uri = new Uri(webCtx.RequestUrl); var uriComps = UriComponents.Scheme | UriComponents.Host; // Check if we need port# var needPort = (uri.Scheme == "http" && uri.Port != 80 || uri.Scheme == "https" && uri.Port != 443); if (needPort) { uriComps |= UriComponents.Port; } var baseAddress = uri.GetComponents(uriComps, UriFormat.Unescaped); settings.RedirectUrl = baseAddress + "/api/oauth_redirect"; }