Skip to content

Instantly share code, notes, and snippets.

@utarn
Created May 7, 2024 22:50
Show Gist options
  • Save utarn/89551ba5c216299ab702ac4d6ca38074 to your computer and use it in GitHub Desktop.
Save utarn/89551ba5c216299ab702ac4d6ca38074 to your computer and use it in GitHub Desktop.
LINE Login
services.AddAuthentication()
.AddOpenIdConnect("Line", "Line", options =>
{
options.CallbackPath = "/signin-line";
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.RequireHttpsMetadata = true;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
CustomOpenIdConnectOptions identityOption = new();
configuration.Bind("Authentication:LineLogin", identityOption);
options.ClientId = identityOption.ClientId;
options.ClientSecret = identityOption.ClientSecret;
options.Configuration = new OpenIdConnectConfiguration()
{
Issuer = "https://access.line.me",
AuthorizationEndpoint = "https://access.line.me/oauth2/v2.1/authorize",
TokenEndpoint = "https://api.line.me/oauth2/v2.1/token",
UserInfoEndpoint = "https://api.line.me/oauth2/v2.1/userinfo"
};
// options.Prompt = "consent";
options.ResponseType = OpenIdConnectResponseType.Code;
options.TokenValidationParameters = new TokenValidationParameters
{
SignatureValidator = delegate(string token, TokenValidationParameters parameters)
{
try
{
var jwt = JWT.Decode<Dictionary<string, object>>(token,
Encoding.UTF8.GetBytes(identityOption.ClientSecret), JwsAlgorithm.HS256);
if (jwt.Count >= 0)
{
// var jwtReturn = new JwtSecurityToken(token);
var returnedToken = new Microsoft.IdentityModel.JsonWebTokens.JsonWebToken(token);
return returnedToken;
// return jwtReturn;
}
else
{
return null;
}
}
catch (Exception)
{
return null;
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment