public static async Task <MyAccessToken> UpdateToken() { var accessToken = await ReadTokenBlob(); var monzoAuth = new MonzoAuthorizationClient("#clientId#", "#clientSecret#"); var ExpiryDate = accessToken.TokenDate.Value.AddSeconds(accessToken.ExpiresIn); var accessTokenConv = new AccessToken(); MyAccessToken myAccessToken = accessToken; if (DateTime.Now > ExpiryDate) { accessTokenConv = await monzoAuth.RefreshAccessTokenAsync(accessToken.RefreshToken); myAccessToken = new MyAccessToken() { ClientId = accessTokenConv.ClientId, ExpiresIn = accessTokenConv.ExpiresIn, RefreshToken = accessTokenConv.RefreshToken, TokenDate = DateTime.Now, TokenType = accessTokenConv.TokenType, UserId = accessTokenConv.UserId, Value = accessTokenConv.Value }; await WriteTokenBlob(myAccessToken); } return(myAccessToken); }
public async Task <ActionResult> Index(LoginModel loginModel) { if (ModelState.IsValid) { LoginBL loginBL = new LoginBL(); loginModel.grant_type = "UserPassword"; string request = JsonConvert.SerializeObject(loginModel); string token = await loginBL.Login(request); MyAccessToken myToken = JsonConvert.DeserializeObject <MyAccessToken>(token); Session["token"] = myToken.access_token; Session["loggedIn"] = "true"; Session["UserName"] = loginModel.UserName; StudentBL studentBL = new StudentBL(); string Users = await studentBL.GetStudents(); List <User_Details> user = JsonConvert.DeserializeObject <List <User_Details> >(Users); foreach (User_Details u in user) { if (u.UserName == loginModel.UserName && u.Category == "Admin") { return(RedirectToAction("Index", "AdminHome")); } else if (u.UserName == loginModel.UserName && u.Category == "Student") { return(RedirectToAction("Index", "Home")); } } return(RedirectToAction("Error", "Login")); } return(View("Index")); }
public static async Task WriteTokenBlob(MyAccessToken orderList) { var blobStorage = new BlobStorage(); var _container = await blobStorage.Create(); var blockBlob = _container.GetBlockBlobReference("monzo.json"); string ordersJson = JsonConvert.SerializeObject(orderList); await blockBlob.UploadTextAsync(ordersJson); }