Skip to content

Commit 55c7c11

Browse files
Add Twitter provider
Add an OAuth 2.0 Twitter provider.
1 parent 3fc71fc commit 55c7c11

15 files changed

+537
-4
lines changed

AspNet.Security.OAuth.Providers.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{C2CA4B38-A
213213
docs\stackexchange.md = docs\stackexchange.md
214214
docs\superoffice.md = docs\superoffice.md
215215
docs\trakt.md = docs\trakt.md
216+
docs\trovo.md = docs\trovo.md
216217
docs\twitch.md = docs\twitch.md
218+
docs\twitter.md = docs\twitter.md
217219
docs\vkontakte.md = docs\vkontakte.md
218220
docs\weibo.md = docs\weibo.md
219221
docs\workweixin.md = docs\workweixin.md
@@ -269,6 +271,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Servi
269271
EndProject
270272
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Security.OAuth.Trovo", "src\AspNet.Security.OAuth.Trovo\AspNet.Security.OAuth.Trovo.csproj", "{DC804C6D-3774-4FA7-8EA6-8C8198995BD6}"
271273
EndProject
274+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Twitter", "src\AspNet.Security.OAuth.Twitter\AspNet.Security.OAuth.Twitter.csproj", "{82314BA9-8AB2-46B9-AB12-9109619B8331}"
275+
EndProject
272276
Global
273277
GlobalSection(SolutionConfigurationPlatforms) = preSolution
274278
Debug|Any CPU = Debug|Any CPU
@@ -611,6 +615,10 @@ Global
611615
{DC804C6D-3774-4FA7-8EA6-8C8198995BD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
612616
{DC804C6D-3774-4FA7-8EA6-8C8198995BD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
613617
{DC804C6D-3774-4FA7-8EA6-8C8198995BD6}.Release|Any CPU.Build.0 = Release|Any CPU
618+
{82314BA9-8AB2-46B9-AB12-9109619B8331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
619+
{82314BA9-8AB2-46B9-AB12-9109619B8331}.Debug|Any CPU.Build.0 = Debug|Any CPU
620+
{82314BA9-8AB2-46B9-AB12-9109619B8331}.Release|Any CPU.ActiveCfg = Release|Any CPU
621+
{82314BA9-8AB2-46B9-AB12-9109619B8331}.Release|Any CPU.Build.0 = Release|Any CPU
614622
EndGlobalSection
615623
GlobalSection(SolutionProperties) = preSolution
616624
HideSolutionNode = FALSE
@@ -706,6 +714,7 @@ Global
706714
{574A52D9-E7A5-4E11-8F36-5C8AA7033287} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
707715
{57633BE6-C7AD-4197-A75A-F38A2312A4D9} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
708716
{DC804C6D-3774-4FA7-8EA6-8C8198995BD6} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
717+
{82314BA9-8AB2-46B9-AB12-9109619B8331} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
709718
EndGlobalSection
710719
GlobalSection(ExtensibilityGlobals) = postSolution
711720
SolutionGuid = {C7B54DE2-6407-4802-AD9C-CE54BF414C8C}

Packages.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<PackageReference Update="JustEat.HttpClientInterception" Version="3.1.1" />
66
<PackageReference Update="MartinCostello.Logging.XUnit" Version="0.2.0" />
77
<PackageReference Update="Microsoft.AspNetCore.Authentication.Google" Version="6.0.0" />
8-
<PackageReference Update="Microsoft.AspNetCore.Authentication.Twitter" Version="6.0.0" />
98
<PackageReference Update="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.0" />
109
<PackageReference Update="Microsoft.AspNetCore.TestHost" Version="6.0.0" />
1110
<PackageReference Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.10.0" />

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
184184
| Trakt | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Trakt?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Trakt/ "Download AspNet.Security.OAuth.Trakt from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Trakt?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Trakt "Download AspNet.Security.OAuth.Trakt from MyGet.org") | [Documentation](https://trakt.docs.apiary.io/ "Trakt developer documentation") |
185185
| Trovo | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Trovo?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Trovo/ "Download AspNet.Security.OAuth.Trovo from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Trovo?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Trovo "Download AspNet.Security.OAuth.Trovo from MyGet.org") | [Documentation](https://developer.trovo.live/docs/APIs.html "Trovo developer documentation") |
186186
| Twitch | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Twitch?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Twitch/ "Download AspNet.Security.OAuth.Twitch from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Twitch?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Twitch "Download AspNet.Security.OAuth.Twitch from MyGet.org") | [Documentation](https://dev.twitch.tv/docs/authentication/ "Twitch developer documentation") |
187+
| Twitter | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Twitter?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Twitter/ "Download AspNet.Security.OAuth.Twitter from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Twitter?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Twitter "Download AspNet.Security.OAuth.Twitter from MyGet.org") | [Documentation](https://developer.twitter.com/en/docs/authentication/oauth-2-0 "Twitter developer documentation") |
187188
| Untappd | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Untappd?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Untappd/ "Download AspNet.Security.OAuth.Untappd from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Untappd?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Untappd "Download AspNet.Security.OAuth.Untappd from MyGet.org") | [Documentation](https://untappd.com/api/docs#authentication "Untappd developer documentation") |
188189
| Vimeo | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Vimeo?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Vimeo/ "Download AspNet.Security.OAuth.Vimeo from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Vimeo?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Vimeo "Download AspNet.Security.OAuth.Vimeo from MyGet.org") | [Documentation](https://developer.vimeo.com/api/authentication "Vimeo developer documentation") |
189190
| Visual Studio (Azure DevOps) | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.VisualStudio?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.VisualStudio/ "Download AspNet.Security.OAuth.VisualStudio from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.VisualStudio?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.VisualStudio "Download AspNet.Security.OAuth.VisualStudio from MyGet.org") | [Documentation](https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops "Azure DevOps developer documentation") |

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ covered by the section above.
6767
| Trakt | _Optional_ | [Documentation](trakt.md "Trakt provider documentation") |
6868
| Trovo | _Optional_ | [Documentation](trovo.md "Trovo provider documentation") |
6969
| Twitch | _Optional_ | [Documentation](twitch.md "Twitch provider documentation") |
70+
| Twitter | _Optional_ | [Documentation](twitter.md "Twitter provider documentation") |
7071
| Vkontakte | _Optional_ | [Documentation](vkontakte.md "Vkontakte provider documentation") |
7172
| Weibo | _Optional_ | [Documentation](weibo.md "Weibo provider documentation") |
7273
| WorkWeixin (WeCom) | _Optional_ | [Documentation](workweixin.md "WorkWeixin provider documentation") |

docs/twitter.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Integrating the Twitter Provider
2+
3+
## Example
4+
5+
```csharp
6+
services.AddAuthentication(options => /* Auth configuration */)
7+
.AddTwitter(options =>
8+
{
9+
options.ClientId = "my-client-id";
10+
options.ClientSecret = "my-client-secret";
11+
12+
// Optionally request additional fields, if needed
13+
options.Expansions.Add("pinned_tweet_id");
14+
options.TweetFields.Add("text");
15+
options.UserFields.Add("created_at");
16+
options.UserFields.Add("pinned_tweet_id");
17+
});
18+
```
19+
20+
## Required Additional Settings
21+
22+
_None._
23+
24+
## Optional Settings
25+
26+
| Property Name | Property Type | Description | Default Value |
27+
|:-:|:-:|:-:|:-:|
28+
| `Expansions` | `ISet<string>` | The optional list of additional data objects to expand from the user information endpoint. | None. |
29+
| `TweetFields` | `ISet<string>` | The optional list of tweet fields to retrieve from the user information endpoint. | None. |
30+
| `UserFields` | `ISet<string>` | The optional list of user fields to retrieve from the user information endpoint. | None. |

samples/Mvc.Client/Mvc.Client.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<ItemGroup>
1414
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
1515
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" />
16-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" />
1716
</ItemGroup>
1817

1918
<Target Name="AddGeneratedContentItems" BeforeTargets="AssignTargetPaths">

samples/Mvc.Client/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public void ConfigureServices(IServiceCollection services)
4444

4545
.AddTwitter(options =>
4646
{
47-
options.ConsumerKey = Configuration["Twitter:ConsumerKey"];
48-
options.ConsumerSecret = Configuration["Twitter:ConsumerSecret"];
47+
options.ClientId = Configuration["Twitter:ClientId"];
48+
options.ClientSecret = Configuration["Twitter:ClientSecret"];
4949
})
5050

5151
.AddGitHub(options =>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageValidationBaselineVersion>6.0.3</PackageValidationBaselineVersion>
5+
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<!-- TODO Remove once published to NuGet.org -->
9+
<PropertyGroup>
10+
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
11+
</PropertyGroup>
12+
13+
<PropertyGroup>
14+
<Description>ASP.NET Core security middleware enabling Twitter authentication.</Description>
15+
<Authors>Martin Costello</Authors>
16+
<PackageTags>aspnetcore;authentication;oauth;security;twitter</PackageTags>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
21+
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
namespace AspNet.Security.OAuth.Twitter;
8+
9+
/// <summary>
10+
/// Contains constants specific to the <see cref="TwitterAuthenticationHandler"/>.
11+
/// </summary>
12+
public static class TwitterAuthenticationConstants
13+
{
14+
/// <summary>
15+
/// Contains claim types specific to Twitter.
16+
/// </summary>
17+
public static class Claims
18+
{
19+
/// <summary>
20+
/// The claim for the friendly name of a user, as shown on their profile.
21+
/// </summary>
22+
public const string Name = "urn:twitter:name";
23+
}
24+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
namespace AspNet.Security.OAuth.Twitter;
8+
9+
/// <summary>
10+
/// Default values used by the Twitter authentication middleware.
11+
/// </summary>
12+
public static class TwitterAuthenticationDefaults
13+
{
14+
/// <summary>
15+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
16+
/// </summary>
17+
public const string AuthenticationScheme = "Twitter";
18+
19+
/// <summary>
20+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
21+
/// </summary>
22+
public static readonly string DisplayName = "Twitter";
23+
24+
/// <summary>
25+
/// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
26+
/// </summary>
27+
public static readonly string Issuer = "Twitter";
28+
29+
/// <summary>
30+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
31+
/// </summary>
32+
public static readonly string CallbackPath = "/signin-twitter";
33+
34+
/// <summary>
35+
/// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
36+
/// </summary>
37+
public static readonly string AuthorizationEndpoint = "https://twitter.com/i/oauth2/authorize";
38+
39+
/// <summary>
40+
/// Default value for <see cref="OAuthOptions.TokenEndpoint"/>.
41+
/// </summary>
42+
public static readonly string TokenEndpoint = "https://api.twitter.com/2/oauth2/token";
43+
44+
/// <summary>
45+
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
46+
/// </summary>
47+
public static readonly string UserInformationEndpoint = "https://api.twitter.com/2/users/me";
48+
}

0 commit comments

Comments
 (0)