Skip to content

Commit 3000125

Browse files
feat: adding endpoint for generating oauth token for desktop app
1 parent 3747a59 commit 3000125

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Nullinside.Api/Controllers/UserController.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,33 @@ public async Task<RedirectResult> TwitchLogin([FromQuery] string code, [FromServ
122122

123123
return Redirect($"{siteUrl}/user/login?token={bearerToken}");
124124
}
125+
126+
/// <summary>
127+
/// **NOT CALLED BY SITE OR USERS** This endpoint is called by twitch as part of their oauth workflow. It
128+
/// redirects users back to the nullinside website.
129+
/// </summary>
130+
/// <param name="code">The credentials provided by twitch.</param>
131+
/// <param name="api">The twitch api.</param>
132+
/// <param name="token">The cancellation token.</param>
133+
/// <returns>
134+
/// A redirect to the nullinside website.
135+
/// Errors:
136+
/// 2 = Internal error generating token.
137+
/// 3 = Code was invalid
138+
/// 4 = Twitch account has no email
139+
/// </returns>
140+
[AllowAnonymous]
141+
[HttpGet]
142+
[Route("twitch-login/twitch-streaming-tools")]
143+
public async Task<RedirectResult> TwitchStreamingToolsLogin([FromQuery] string code, [FromServices] ITwitchApiProxy api,
144+
CancellationToken token = new()) {
145+
string? siteUrl = _configuration.GetValue<string>("Api:SiteUrl");
146+
if (null == await api.CreateAccessToken(code, token)) {
147+
return Redirect($"{siteUrl}/user/login?error=3");
148+
}
149+
150+
return Redirect($"{siteUrl}/user/login?token={api.OAuth?.AccessToken}&refresh={api.OAuth?.RefreshToken}&expiresUtc={api.OAuth?.ExpiresUtc?.ToString()}&desktop=true");
151+
}
125152

126153
/// <summary>
127154
/// Gets the roles of the current user.

0 commit comments

Comments
 (0)