a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[backend/masto-client] Add endpoint to get a web API token that's linked to a Mastodon session

authored by

pancakes and committed by
Laura Hausmann
7699b5e9 a1d1a564

+32 -1
+31
Iceshrimp.Backend/Controllers/Mastodon/AccountController.cs
··· 11 11 using Iceshrimp.Backend.Core.Database; 12 12 using Iceshrimp.Backend.Core.Database.Tables; 13 13 using Iceshrimp.Backend.Core.Extensions; 14 + using Iceshrimp.Backend.Core.Helpers; 14 15 using Iceshrimp.Backend.Core.Middleware; 15 16 using Iceshrimp.Backend.Core.Services; 16 17 using Iceshrimp.Shared.Helpers; ··· 128 129 129 130 user = await userSvc.UpdateLocalUserAsync(user, prevAvatarId, prevBannerId); 130 131 return await userRenderer.RenderAsync(user, user.UserProfile, user, source: true); 132 + } 133 + 134 + [HttpPost("authorize_iceshrimp")] 135 + [Authorize("iceshrimp")] 136 + [ProducesResults(HttpStatusCode.OK)] 137 + public async Task<string> AuthorizeIceshrimpToken() 138 + { 139 + var user = HttpContext.GetUserOrFail(); 140 + var token = HttpContext.GetOauthToken() ?? throw new Exception("Failed to get user from HttpContext"); 141 + 142 + var webSession = await db.OauthTokens 143 + .Where(p => p.Id == token.Id) 144 + .Select(p => p.WebSession) 145 + .FirstAsync(); 146 + 147 + if (webSession != null) return webSession.Token; 148 + 149 + var session = new Session 150 + { 151 + Id = IdHelpers.GenerateSnowflakeId(), 152 + UserId = user.Id, 153 + Active = true, 154 + CreatedAt = DateTime.UtcNow, 155 + Token = CryptographyHelpers.GenerateRandomString(32), 156 + MastodonToken = token 157 + }; 158 + await db.AddAsync(session); 159 + await db.SaveChangesAsync(); 160 + 161 + return session.Token; 131 162 } 132 163 133 164 [HttpDelete("/api/v1/profile/avatar")]
+1 -1
Iceshrimp.Backend/Core/Helpers/MastodonOauthHelpers.cs
··· 93 93 { 94 94 if (scopes.Distinct().Count() < scopes.Count) return false; 95 95 96 - var validScopes = ScopeGroups.Concat(ReadScopes).Concat(WriteScopes).Concat(FollowScopes); 96 + var validScopes = ScopeGroups.Concat(ReadScopes).Concat(WriteScopes).Concat(FollowScopes).Append("iceshrimp"); 97 97 return !scopes.Except(validScopes).Any(); 98 98 } 99 99