コード例 #1
0
        public HomeController( )
        {
            var appFactory = new D2LAppContextFactory();

            m_valenceAppContext = appFactory.Create(APP_ID, APP_KEY);
            m_valenceHost       = new HostSpec("https", LMS_URL, 443);
        }
コード例 #2
0
        private static ID2LAppContext CreateAppContextWithDelay(string appId, string appKey, long delaySeconds)
        {
            var timestampProvider = CreateTimestampProviderDelay(delaySeconds);
            var factory           = new D2LAppContextFactory(timestampProvider);

            return(factory.Create(appId, appKey));
        }
コード例 #3
0
ファイル: FactoryTests.cs プロジェクト: shafe123/D2L-client
		public void AppContextFactory_Create_ReturnedObject_Implements_ID2LAppContext() {
			var factory = new D2LAppContextFactory();

			var context = factory.Create( "foo", "bar" );

			Assert.IsInstanceOf<ID2LAppContext>( context );
		}
コード例 #4
0
        static void Main()
        {
            // This is the LMS we will interact with
            var host = new HostSpec("https", "lms.valence.desire2learn.com", 443);

            // The appId/appKey come from our app.config - it is good to seperate access keys from the code that uses them.
            // Ideally you wouldn't have production keys committed to source control.
            string appId  = ConfigurationManager.AppSettings["appId"];
            string appKey = ConfigurationManager.AppSettings["appKey"];

            // This is the port we will temporarily host a server on to intercept the user tokens after a successful login
            int port = int.Parse(ConfigurationManager.AppSettings["serverPort"]);

            // Create url for the user to login. If they have already done so they will not actually have to type their password (maybe).
            var appContextFactory = new D2LAppContextFactory();
            var appContext        = appContextFactory.Create(appId, appKey);
            var authUrl           = appContext.CreateUrlForAuthentication(host, new Uri("http://localhost:" + port + "/result/"));

            OpenBrowser(authUrl);

            // This call will block until we have a result
            // TODO: you'll want better control flow and error handling here
            var userContext = InterceptUserTokens(host, appContext);

            // Now we can call Valence
            DoApiStuff(host.Scheme + "://" + host.Host + ":" + host.Port, userContext);

            // Pause the terminal
            Console.ReadKey();
        }
コード例 #5
0
        public HomeController( )
        {
            var appFactory = new D2LAppContextFactory();

            m_valenceAppContext = appFactory.Create(m_appId, m_appKey);
            m_valenceHost       = new HostSpec("https", LMS_URL, 443);
        }
コード例 #6
0
        internal static ID2LAppContext CreateAppContextUnderTest(ITimestampProvider timestampProvider = null)
        {
            timestampProvider = timestampProvider ?? new DefaultTimestampProvider();
            var factory = new D2LAppContextFactory(timestampProvider);

            return(factory.Create(TestConstants.APP_ID, TestConstants.APP_KEY));
        }
コード例 #7
0
        public ActionResult Index()
        {
            var param = Session[SESSION_KEY] as SessionParameters;

            if (param == null)
            {
                ViewBag.ErrorMessage = "Unable to retrieve required session param.";
                return(View("BookError"));
            }

            if (param.LtiUri == null)
            {
                ViewBag.ErrorMessage = "LTI param are not valid.";
                return(View("BookError"));
            }

            // retrieve the required version information from the LMS
            var factory    = new D2LAppContextFactory();
            var appContext = factory.Create(m_defaultAppId, m_defaultAppKey);
            var hostInfo   = new HostSpec(param.LtiUri.Scheme, param.LtiUri.Host, param.LtiUri.Port);

            ID2LUserContext context = appContext.CreateUserContext(Request.Url, hostInfo);

            if (context == null)
            {
                ViewBag.ErrorMessage = "Unable to create user context.";
                return(View("BookError"));
            }

            param.UserContext = context;

            return(RedirectToAction("Assigned"));
        }
コード例 #8
0
        public void AppContextFactory_Create_ReturnedObject_Implements_ID2LAppContext()
        {
            var factory = new D2LAppContextFactory();

            var context = factory.Create("foo", "bar");

            Assert.IsInstanceOf <ID2LAppContext>(context);
        }
コード例 #9
0
        public ValenceAuthenticator CreateAuthenticator()
        {
            D2LAppContextFactory contextFactory = new D2LAppContextFactory();
            ID2LAppContext       appContext     = contextFactory.Create(m_appId, m_appKey);
            HostSpec             valenceHost    = new HostSpec("https", m_lmsUrl, 443);
            ID2LUserContext      userContext    = appContext.CreateUserContext(m_userId, m_userKey, valenceHost);

            return(new ValenceAuthenticator(userContext));
        }
コード例 #10
0
        /*
         * Creates a new ID2LUserContext object
         *
         * @return
         *      an instance of a ID2LUserContext
         */
        public static ID2LUserContext GetD2LUserContext()
        {
            D2LAppContextFactory factory     = new D2LAppContextFactory();
            ID2LAppContext       appContext  = factory.Create(Utility.GetAppIdValence(), Utility.GetAppKeyValence());
            HostSpec             hostInfo    = new HostSpec(Utility.GetSchemaValence(), Utility.GetHostValence(), Utility.GetPortValence());
            ID2LUserContext      userContext = appContext.CreateUserContext(Utility.GetUserIdValence(), Utility.GetUserKeyValence(), hostInfo);

            return(userContext);
        }
コード例 #11
0
        public void SetUpUserContext()
        {
            var factory = new D2LAppContextFactory();

            m_appContext = factory.Create(m_appId, m_appKey);
            var apiHost = GetDefaultApiHost();

            m_userContext    = m_appContext.CreateUserContext(m_userId, m_userKey, apiHost);
            m_anonContext    = m_appContext.CreateAnonymousUserContext(apiHost);
            m_badUserContext = m_appContext.CreateUserContext("foo", "bar", apiHost);
        }
コード例 #12
0
        public Context(Configuration config)
        {
            var appFactory = new D2LAppContextFactory();

            ValenceAppContext = appFactory.Create(config["appId"], config["appKey"]);
            ValenceHost       = new HostSpec("https", config["lmsUrl"], 443);
            Client            = new RestClient("https://" + config["lmsUrl"]);

            if (File.Exists(".bs-auth"))
            {
                ValenceUserContext = ValenceAppContext.CreateUserContext(new Uri(File.ReadAllText(".bs-auth")), ValenceHost);
            }
            else
            {
                ValenceUserContext = null;
            }
        }
コード例 #13
0
        private Uri GenerateAuthRedirect(Uri returnUri, Uri requestUri)
        {
            if ((requestUri == null) || (returnUri == null))
            {
                throw new ArgumentNullException();
            }

            var factory    = new D2LAppContextFactory();
            var appContext = factory.Create(m_defaultAppId, m_defaultAppKey);

            var resultUri = new UriBuilder(requestUri.Scheme,
                                           requestUri.Host,
                                           requestUri.Port,
                                           requestUri.AbsolutePath).Uri;

            var host        = new HostSpec(returnUri.Scheme, returnUri.Host, returnUri.Port);
            var redirectUri = appContext.CreateUrlForAuthentication(host, resultUri);

            return(redirectUri);
        }
コード例 #14
0
 private static ID2LAppContext CreateAppContextWithDelay( string appId, string appKey, long delaySeconds )
 {
     var timestampProvider = CreateTimestampProviderDelay( delaySeconds );
     var factory = new D2LAppContextFactory( timestampProvider );
     return factory.Create( appId, appKey );
 }
コード例 #15
0
 static ContextProvider()
 {
     m_appContextFactory = new D2LAppContextFactory();
     m_appContext        = m_appContextFactory.Create(ConfigHelper.AppId, ConfigHelper.AppKey);
 }
コード例 #16
0
ファイル: TestUtils.cs プロジェクト: shafe123/D2L-client
		internal static ID2LAppContext CreateAppContextUnderTest() {
			var factory = new D2LAppContextFactory();
			return factory.Create( TestConstants.APP_ID, TestConstants.APP_KEY );
		}
コード例 #17
0
 internal static ID2LAppContext CreateAppContextUnderTest( ITimestampProvider timestampProvider = null )
 {
     timestampProvider = timestampProvider ?? new DefaultTimestampProvider();
     var factory = new D2LAppContextFactory( timestampProvider );
     return factory.Create( TestConstants.APP_ID, TestConstants.APP_KEY );
 }