Beispiel #1
0
        private string GetRawToken()
        {
            string rawToken     = OAuthClientModule.GetAccessToken(this._realm, false);
            var    tokenHandler = new SimpleWebTokenHandler();
            var    token        = tokenHandler.ReadToken(Encoding.ASCII.GetString(Convert.FromBase64String(rawToken)));

            if (DateTime.Compare(token.ValidTo, DateTime.UtcNow.Add(_skew)) <= 0)
            {
                rawToken = OAuthClientModule.GetAccessToken(this._realm, true);
            }

            return(rawToken);
        }
Beispiel #2
0
        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));
        }