Skip to content

Commit 3832019

Browse files
committed
Update Facebook to v3.1 endpoints #92
1 parent 862f781 commit 3832019

File tree

8 files changed

+28
-13
lines changed

8 files changed

+28
-13
lines changed

samples/SocialSample/Startup.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public void ConfigureServices(IServiceCollection services)
5959
.AddCookie(o => o.LoginPath = new PathString("/login"))
6060
// You must first create an app with Facebook and add its ID and Secret to your user-secrets.
6161
// https://developers.facebook.com/apps/
62+
// https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#login
6263
.AddFacebook(o =>
6364
{
6465
o.AppId = Configuration["facebook:appid"];
@@ -74,6 +75,8 @@ public void ConfigureServices(IServiceCollection services)
7475
})
7576
// You must first create an app with Google and add its ID and Secret to your user-secrets.
7677
// https://console.developers.google.com/project
78+
// https://developers.google.com/identity/protocols/OAuth2WebServer
79+
// https://developers.google.com/+/web/people/
7780
.AddOAuth("Google-AccessToken", "Google AccessToken only", o =>
7881
{
7982
o.ClientId = Configuration["google:clientid"];
@@ -92,6 +95,8 @@ public void ConfigureServices(IServiceCollection services)
9295
})
9396
// You must first create an app with Google and add its ID and Secret to your user-secrets.
9497
// https://console.developers.google.com/project
98+
// https://developers.google.com/identity/protocols/OAuth2WebServer
99+
// https://developers.google.com/+/web/people/
95100
.AddGoogle(o =>
96101
{
97102
o.ClientId = Configuration["google:clientid"];
@@ -108,6 +113,7 @@ public void ConfigureServices(IServiceCollection services)
108113
})
109114
// You must first create an app with Twitter and add its key and Secret to your user-secrets.
110115
// https://apps.twitter.com/
116+
// https://developer.twitter.com/en/docs/basics/authentication/api-reference/access_token
111117
.AddTwitter(o =>
112118
{
113119
o.ConsumerKey = Configuration["twitter:consumerkey"];

src/Microsoft.AspNetCore.Authentication.Facebook/FacebookDefaults.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ public static class FacebookDefaults
99

1010
public static readonly string DisplayName = "Facebook";
1111

12-
public static readonly string AuthorizationEndpoint = "https://www.facebook.com/v2.12/dialog/oauth";
12+
// https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#login
13+
public static readonly string AuthorizationEndpoint = "https://www.facebook.com/v3.1/dialog/oauth";
1314

14-
public static readonly string TokenEndpoint = "https://graph.facebook.com/v2.12/oauth/access_token";
15+
public static readonly string TokenEndpoint = "https://graph.facebook.com/v3.1/oauth/access_token";
1516

16-
public static readonly string UserInformationEndpoint = "https://graph.facebook.com/v2.12/me";
17+
public static readonly string UserInformationEndpoint = "https://graph.facebook.com/v3.1/me";
1718
}
1819
}

src/Microsoft.AspNetCore.Authentication.Facebook/FacebookOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public FacebookOptions()
2626
AuthorizationEndpoint = FacebookDefaults.AuthorizationEndpoint;
2727
TokenEndpoint = FacebookDefaults.TokenEndpoint;
2828
UserInformationEndpoint = FacebookDefaults.UserInformationEndpoint;
29-
Scope.Add("public_profile");
3029
Scope.Add("email");
3130
Fields.Add("name");
3231
Fields.Add("email");

src/Microsoft.AspNetCore.Authentication.Google/GoogleDefaults.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ public static class GoogleDefaults
1212

1313
public static readonly string DisplayName = "Google";
1414

15+
// https://developers.google.com/identity/protocols/OAuth2WebServer
1516
public static readonly string AuthorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
1617

1718
public static readonly string TokenEndpoint = "https://www.googleapis.com/oauth2/v4/token";
1819

20+
// https://developers.google.com/+/web/people/
1921
public static readonly string UserInformationEndpoint = "https://www.googleapis.com/plus/v1/people/me";
2022
}
2123
}

src/Microsoft.AspNetCore.Authentication.MicrosoftAccount/MicrosoftAccountDefaults.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class MicrosoftAccountDefaults
99

1010
public static readonly string DisplayName = "Microsoft";
1111

12+
// https://developer.microsoft.com/en-us/graph/docs/concepts/auth_v2_user
1213
public static readonly string AuthorizationEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
1314

1415
public static readonly string TokenEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/token";

src/Microsoft.AspNetCore.Authentication.Twitter/TwitterDefaults.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,14 @@ public static class TwitterDefaults
88
public const string AuthenticationScheme = "Twitter";
99

1010
public static readonly string DisplayName = "Twitter";
11+
12+
// https://developer.twitter.com/en/docs/basics/authentication/api-reference/request_token
13+
internal const string RequestTokenEndpoint = "https://api.twitter.com/oauth/request_token";
14+
15+
// https://developer.twitter.com/en/docs/basics/authentication/api-reference/authenticate
16+
internal const string AuthenticationEndpoint = "https://api.twitter.com/oauth/authenticate?oauth_token=";
17+
18+
// https://developer.twitter.com/en/docs/basics/authentication/api-reference/access_token
19+
internal const string AccessTokenEndpoint = "https://api.twitter.com/oauth/access_token";
1120
}
1221
}

src/Microsoft.AspNetCore.Authentication.Twitter/TwitterHandler.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ namespace Microsoft.AspNetCore.Authentication.Twitter
2222
public class TwitterHandler : RemoteAuthenticationHandler<TwitterOptions>
2323
{
2424
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
25-
private const string RequestTokenEndpoint = "https://api.twitter.com/oauth/request_token";
26-
private const string AuthenticationEndpoint = "https://api.twitter.com/oauth/authenticate?oauth_token=";
27-
private const string AccessTokenEndpoint = "https://api.twitter.com/oauth/access_token";
2825

2926
private HttpClient Backchannel => Options.Backchannel;
3027

@@ -138,7 +135,7 @@ protected override async Task HandleChallengeAsync(AuthenticationProperties prop
138135

139136
// If CallbackConfirmed is false, this will throw
140137
var requestToken = await ObtainRequestTokenAsync(BuildRedirectUri(Options.CallbackPath), properties);
141-
var twitterAuthenticationEndpoint = AuthenticationEndpoint + requestToken.Token;
138+
var twitterAuthenticationEndpoint = TwitterDefaults.AuthenticationEndpoint + requestToken.Token;
142139

143140
var cookieOptions = Options.StateCookie.Build(Context, Clock.UtcNow);
144141

@@ -233,7 +230,7 @@ private async Task<RequestToken> ObtainRequestTokenAsync(string callBackUri, Aut
233230
{
234231
Logger.ObtainRequestToken();
235232

236-
var response = await ExecuteRequestAsync(RequestTokenEndpoint, HttpMethod.Post, extraOAuthPairs: new Dictionary<string, string>() { { "oauth_callback", callBackUri } });
233+
var response = await ExecuteRequestAsync(TwitterDefaults.RequestTokenEndpoint, HttpMethod.Post, extraOAuthPairs: new Dictionary<string, string>() { { "oauth_callback", callBackUri } });
237234
response.EnsureSuccessStatusCode();
238235
var responseText = await response.Content.ReadAsStringAsync();
239236

@@ -253,7 +250,7 @@ private async Task<AccessToken> ObtainAccessTokenAsync(RequestToken token, strin
253250
Logger.ObtainAccessToken();
254251

255252
var formPost = new Dictionary<string, string> { { "oauth_verifier", verifier } };
256-
var response = await ExecuteRequestAsync(AccessTokenEndpoint, HttpMethod.Post, token, formData: formPost);
253+
var response = await ExecuteRequestAsync(TwitterDefaults.AccessTokenEndpoint, HttpMethod.Post, token, formData: formPost);
257254

258255
if (!response.IsSuccessStatusCode)
259256
{

test/Microsoft.AspNetCore.Authentication.Test/FacebookTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ public async Task NestedMapWillNotAffectRedirect()
673673
var transaction = await server.SendAsync("http://example.com/base/login");
674674
Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode);
675675
var location = transaction.Response.Headers.Location.AbsoluteUri;
676-
Assert.Contains("https://www.facebook.com/v2.12/dialog/oauth", location);
676+
Assert.Contains("https://www.facebook.com/v3.1/dialog/oauth", location);
677677
Assert.Contains("response_type=code", location);
678678
Assert.Contains("client_id=", location);
679679
Assert.Contains("redirect_uri=" + UrlEncoder.Default.Encode("http://example.com/base/signin-facebook"), location);
@@ -705,7 +705,7 @@ public async Task MapWillNotAffectRedirect()
705705
var transaction = await server.SendAsync("http://example.com/login");
706706
Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode);
707707
var location = transaction.Response.Headers.Location.AbsoluteUri;
708-
Assert.Contains("https://www.facebook.com/v2.12/dialog/oauth", location);
708+
Assert.Contains("https://www.facebook.com/v3.1/dialog/oauth", location);
709709
Assert.Contains("response_type=code", location);
710710
Assert.Contains("client_id=", location);
711711
Assert.Contains("redirect_uri=" + UrlEncoder.Default.Encode("http://example.com/signin-facebook"), location);
@@ -739,7 +739,7 @@ public async Task ChallengeWillTriggerRedirection()
739739
var transaction = await server.SendAsync("http://example.com/challenge");
740740
Assert.Equal(HttpStatusCode.Redirect, transaction.Response.StatusCode);
741741
var location = transaction.Response.Headers.Location.AbsoluteUri;
742-
Assert.Contains("https://www.facebook.com/v2.12/dialog/oauth", location);
742+
Assert.Contains("https://www.facebook.com/v3.1/dialog/oauth", location);
743743
Assert.Contains("response_type=code", location);
744744
Assert.Contains("client_id=", location);
745745
Assert.Contains("redirect_uri=", location);

0 commit comments

Comments
 (0)