private async Task SignIn(string username) { string hash; using (var md5 = MD5.Create()) { hash = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(username))).Replace("-", "").ToLower(); } var user = new User { Username = username, Name = username, Email = username, ImageUrl = $"https://www.gravatar.com/avatar/{hash}" }; await authority.SignIn(user, HttpContext); }
public async Task <IActionResult> GetRedirect(string code) { using (var httpClient = new HttpClient()) { string accessUrl = $"https://slack.com/api/oauth.access?client_id={config.SlackClientId}&client_secret={config.SlackSecret}&code={code}&redirect_uri={GetRedirectUrl()}"; var response = await httpClient.GetAsync(accessUrl); response.EnsureSuccessStatusCode(); var resultBody = await response.Content.ReadAsStringAsync(); var result = DeserializeResultBody(resultBody); if (!result.Ok) { throw new InvalidOperationException(); } var principal = await authority.SignIn(result.User, HttpContext); await userRepository.CreateUserIfNotExists(principal); return(Redirect("/")); } }