public async Task <ActionResult> Authorize(string token) { var db = FirestoreDb.Create("unify-database"); // Authenticate the user var authentication = await _spotifyService.Authenticate(token); // Set the authorization var userService = await _spotifyService.GetUserService(authentication.AccessToken); var profile = await userService.GetUserProfile(); var docRef = db.Collection("Users").Document($"{profile.Id}"); var User = new User() { DisplayName = profile.DisplayName, SpotifyAccessToken = authentication.AccessToken, SpotifyRefreshToken = authentication.RefreshToken }; await docRef.SetAsync(User); // Return something that is unique to the user and that the backend can use to retrieve their data return(Ok(profile)); }
public async Task <IActionResult> Route() { if (Request.Query.ContainsKey("error") || !Request.Query.ContainsKey("code")) { var returnMessage = "Error has occured while trying to get authorization:\n"; returnMessage += Request.Query["state"]; return(Content(returnMessage)); } var response = await _service.Authenticate(Request.Query["code"]); if (response == null) { return(Redirect("/dashboard")); } var ret = "Error has occured while trying to get authorization:\n"; ret += response; return(Content(ret)); }