public HomeController( ) { var appFactory = new D2LAppContextFactory(); m_valenceAppContext = appFactory.Create(APP_ID, APP_KEY); m_valenceHost = new HostSpec("https", LMS_URL, 443); }
private static ID2LAppContext CreateAppContextWithDelay(string appId, string appKey, long delaySeconds) { var timestampProvider = CreateTimestampProviderDelay(delaySeconds); var factory = new D2LAppContextFactory(timestampProvider); return(factory.Create(appId, appKey)); }
public void AppContextFactory_Create_ReturnedObject_Implements_ID2LAppContext() { var factory = new D2LAppContextFactory(); var context = factory.Create( "foo", "bar" ); Assert.IsInstanceOf<ID2LAppContext>( context ); }
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(); }
public HomeController( ) { var appFactory = new D2LAppContextFactory(); m_valenceAppContext = appFactory.Create(m_appId, m_appKey); m_valenceHost = new HostSpec("https", LMS_URL, 443); }
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)); }
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")); }
public void AppContextFactory_Create_ReturnedObject_Implements_ID2LAppContext() { var factory = new D2LAppContextFactory(); var context = factory.Create("foo", "bar"); Assert.IsInstanceOf <ID2LAppContext>(context); }
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)); }
/* * 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); }
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); }
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; } }
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); }
private static ID2LAppContext CreateAppContextWithDelay( string appId, string appKey, long delaySeconds ) { var timestampProvider = CreateTimestampProviderDelay( delaySeconds ); var factory = new D2LAppContextFactory( timestampProvider ); return factory.Create( appId, appKey ); }
static ContextProvider() { m_appContextFactory = new D2LAppContextFactory(); m_appContext = m_appContextFactory.Create(ConfigHelper.AppId, ConfigHelper.AppKey); }
internal static ID2LAppContext CreateAppContextUnderTest() { var factory = new D2LAppContextFactory(); return factory.Create( TestConstants.APP_ID, TestConstants.APP_KEY ); }
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 ); }