Skip to content

Commit 124d1fe

Browse files
committed
add line login
1 parent 005462b commit 124d1fe

File tree

93 files changed

+74849
-17
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+74849
-17
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,30 @@ using (var client = new LineLiffClient("access token"))
221221
|[Get all LIFF apps](https://developers.line.biz/en/reference/liff-server/#get-all-liff-apps)|GetAllLiffAppsAsync|✔|
222222
|[Delete LIFF app from a channel](https://developers.line.biz/en/reference/liff-server/#delete-liff-app)|DeleteLiffAppsFromChannelAsync|✔|
223223
224+
## 2-4 LineLoginClient
225+
* [LINE Login v2.1](https://developers.line.biz/en/reference/line-login/)
226+
227+
```csharp
228+
using Line.Login;
229+
230+
using (LineLoginClient client = new LineLoginClient())
231+
{
232+
var issued = await client.OAuth2dot1.IssueAccessTokenAsync("code", "redirectUrl", "clientId", "secret");
233+
var profile = await client.GetUserProfileAsync(issued.AccessToken);
234+
}
235+
```
236+
237+
|LINE Developers|Methods|Tested|
238+
|---|---|---|
239+
|[Issue access token](https://developers.line.biz/en/reference/line-login/#issue-access-token)|OAuth2dot1.IssueAccessTokenAsync|✔|
240+
|[Verify access token validity](https://developers.line.biz/en/reference/line-login/#verify-access-token)|OAuth2dot1.VerifyAccessTokenValidityAsync|✔|
241+
|[Refresh access token](https://developers.line.biz/en/reference/line-login/#refresh-access-token)|OAuth2dot1.RefreshAccessTokenAsync|✔|
242+
|[Revoke access token](https://developers.line.biz/en/reference/line-login/#revoke-access-token)|OAuth2dot1.RevokeAccessTokenAsync|✔|
243+
|[Verify ID token](https://developers.line.biz/en/reference/line-login/#verify-id-token)|OAuth2dot1.VerifyIdTokenAsync|✔|
244+
|[Get user information](https://developers.line.biz/en/reference/line-login/#userinfo)|OAuth2dot1.GetUserInformationAsync|✔|
245+
|[Get user profile](https://developers.line.biz/en/reference/line-login/#get-user-profile)|GetUserProfileAsync|✔|
246+
|[Get friendship status](https://developers.line.biz/en/reference/line-login/#get-friendship-status)|GetFriendshipStatusAsync|✔|
247+
224248
# 3. reference doc
225249
* [Messaging API reference](https://developers.line.biz/en/reference/messaging-api/)
226250
* [How to serialize properties of derived classes with System.Text.Json](https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism?pivots=dotnet-7-0)

Src/LineDevelopers.ConsoleTests/Program.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json;
22
using Line;
3+
using Line.Login;
34
using Line.Message;
45

56
var json = File.ReadAllText(@"c:\temp\test.json");
@@ -8,13 +9,19 @@
89

910

1011

12+
using (LineLoginClient client = new LineLoginClient())
13+
{
14+
var issued = await client.OAuth2dot1.IssueAccessTokenAsync("code", "redirectUrl", "clientId", "secret");
15+
var profile = await client.GetUserProfileAsync(issued.AccessToken);
16+
}
17+
1118

12-
using (var client = new LineMessagingClient(config.ChannelAccessToken))
19+
using (var client2 = new LineMessagingClient(config.ChannelAccessToken))
1320
{
1421
try
1522
{
1623

17-
var result = await client.Bot.GetBotInformationAsync();
24+
var result = await client2.Bot.GetBotInformationAsync();
1825

1926
Console.WriteLine(result.PremiumId);
2027
Console.WriteLine(result.PictureUrl);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\LineDevelopers\LineDevelopers.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@page
2+
@model LineDevelopers.OAuth.Tests.Pages.CallbackModel
3+
@{
4+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System.Web;
2+
using Line;
3+
using Line.Login;
4+
using Microsoft.AspNetCore.Mvc.RazorPages;
5+
6+
namespace LineDevelopers.OAuth.Tests.Pages
7+
{
8+
public class CallbackModel : PageModel
9+
{
10+
public async Task OnGet()
11+
{
12+
string clientId = "";
13+
string secret = "";
14+
15+
using (LineLoginClient client = new LineLoginClient())
16+
{
17+
var code = Request.Query["code"];
18+
19+
var issued = await client.OAuth2dot1.IssueAccessTokenAsync(code,
20+
HttpUtility.HtmlEncode("https://2100-175-113-116-30.ngrok-free.app/Callback"),
21+
clientId,
22+
secret);
23+
24+
25+
var verifyToken = await client.OAuth2dot1.VerifyAccessTokenValidityAsync(issued.AccessToken);
26+
27+
var verifyScope = verifyToken.Scope;
28+
var verifyClientId = verifyToken.ClientId;
29+
var verifyExpiresIn = verifyToken.ExpiresIn;
30+
31+
var verifyIdToken = await client.OAuth2dot1.VerifyIdTokenAsync(issued.IdToken, clientId);
32+
33+
var iss = verifyIdToken.Iss;
34+
var sub = verifyIdToken.Sub;
35+
var aud = verifyIdToken.Aud;
36+
37+
var user = await client.OAuth2dot1.GetUserInformationAsync(issued.AccessToken);
38+
39+
var userSub = user.Sub;
40+
var userName = user.Name;
41+
42+
var profile = await client.GetUserProfileAsync(issued.AccessToken);
43+
44+
var profileName = profile.DisplayName;
45+
46+
var friendship = await client.GetFriendshipStatusAsync(issued.AccessToken);
47+
48+
49+
await client.OAuth2dot1.RevokeAccessTokenAsync(issued.AccessToken, clientId, secret);
50+
51+
try
52+
{
53+
var refresh = await client.OAuth2dot1.RefreshAccessTokenAsync(issued.RefreshToken, clientId, secret);
54+
55+
var refreshAccess = refresh.AccessToken;
56+
57+
}
58+
catch (LineCredentialException ex)
59+
{
60+
var msg = ex.Message;
61+
var detail = ex.Detail;
62+
}
63+
64+
}
65+
66+
67+
}
68+
}
69+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
5+
namespace LineDevelopers.OAuth.Tests.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
7+
<div class="text-center">
8+
<h1 class="display-4">Welcome</h1>
9+
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
10+
<a href="https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=1661292873&redirect_uri=https://2100-175-113-116-30.ngrok-free.app/Callback&state=45645646abcde&scope=profile%20openid&nonce=09876xyz">
11+
LOGIN
12+
</a>
13+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace LineDevelopers.OAuth.Tests.Pages
5+
{
6+
public class IndexModel : PageModel
7+
{
8+
private readonly ILogger<IndexModel> _logger;
9+
10+
public IndexModel(ILogger<IndexModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
18+
}
19+
}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>

0 commit comments

Comments
 (0)