This repository was archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthController.cs
More file actions
61 lines (47 loc) · 1.76 KB
/
Copy pathAuthController.cs
File metadata and controls
61 lines (47 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using LINELoginOIDCImplementationDemo.Models;
using LINELoginOIDCImplementationDemo.Models.Interface;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
namespace LINELoginOIDCImplementationDemo.Controllers;
[AllowAnonymous]
public class AuthController : Controller
{
private readonly Authentication _auth;
public AuthController(Authentication auth)
{
_auth = auth;
}
public IActionResult Login()
{
//_auth.SetupRedirectUri(Request);
return Redirect(_auth.AuthorizeUrl);
}
public async Task<IActionResult> SigninOIDCAsync(SigninOIDCResponse signin)
{
//_auth.SetupRedirectUri(Request);
if (signin.state != _auth.State)
{
return BadRequest("State not match!");
}
if (!string.IsNullOrEmpty(signin.error))
{
ISigninOIDCResponse_Error err = signin;
return BadRequest($"{err.error}: {err.error_description}");
}
ISigninOIDCResponse_Success success = signin;
string code = success.code;
ITokenResponse token = await _auth.GetTokenAsync(code);
IVerifyResponse verify = await _auth.VerifyTokenAsync(token);
ClaimsIdentity claimsIdentity = Authentication.MakeClaimsIdentity(verify);
AuthenticationProperties authenticationProperties = Authentication.MakeAuthenticationProperties(token,verify);
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authenticationProperties
);
return RedirectToAction("Index", "Home");
}
}