-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from granthoff1107/master
OnRefresh callback support.
- Loading branch information
Showing
9 changed files
with
119 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
...nbase.Tests/Endpoints/OAuthHelperTests.cs → ...base.Tests/OAuthTests/OAuthHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Net.Http; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Coinbase.Tests.OAuthTests | ||
{ | ||
public class TokenTests : OAuthServerTest | ||
{ | ||
|
||
[Test] | ||
public async Task auto_refresh_token() | ||
{ | ||
//simulate the expired response. | ||
var expiredResponse = @"{""errors"":[{""id"":""expired_token"",""message"":""The access token is expired""}]}"; | ||
server.RespondWith(expiredResponse, status:401); | ||
|
||
|
||
//simulate the refresh response. | ||
var refreshResponse = @"{ | ||
""access_token"":""aaa"", | ||
""token_type"":""bearer"", | ||
""expires_in"":7200, | ||
""refresh_token"":""bbb"", | ||
""scope"":""all"", | ||
""created_at"":1542649114 | ||
}"; | ||
server.RespondWith(refreshResponse, status: 200); | ||
|
||
//simulate the actual successful response after token refresh. | ||
SetupServerSingleResponse(Examples.User); | ||
|
||
//enable automatic refresh | ||
client.WithAutomaticOAuthTokenRefresh("clientId", "clientSecret"); | ||
|
||
var response = await client.Users.GetCurrentUserAsync(); | ||
|
||
response.Dump(); | ||
|
||
var config = client.Config as OAuthConfig; | ||
config.AccessToken.Should().Be("aaa"); | ||
config.RefreshToken.Should().Be("bbb"); | ||
|
||
Examples.UserModel.Should().BeEquivalentTo(response.Data); | ||
} | ||
|
||
[Test] | ||
public async Task auto_refresh_token_with_callback() | ||
{ | ||
//simulate the expired response. | ||
var expiredResponse = @"{""errors"":[{""id"":""expired_token"",""message"":""The access token is expired""}]}"; | ||
server.RespondWith(expiredResponse, status: 401); | ||
|
||
//simulate the refresh response. | ||
var refreshResponse = @"{ | ||
""access_token"":""aaa"", | ||
""token_type"":""bearer"", | ||
""expires_in"":7200, | ||
""refresh_token"":""bbb"", | ||
""scope"":""all"", | ||
""created_at"":1542649114 | ||
}"; | ||
server.RespondWith(refreshResponse, status: 200); | ||
|
||
//simulate the actual successful response after token refresh. | ||
SetupServerSingleResponse(Examples.User); | ||
|
||
//enable automatic refresh | ||
client.WithAutomaticOAuthTokenRefresh("clientId", "clientSecret", o => | ||
{ | ||
o.AccessToken.Should().Be("aaa"); | ||
o.RefreshToken.Should().Be("bbb"); | ||
return Task.FromResult(0); | ||
}); | ||
|
||
var response = await client.Users.GetCurrentUserAsync(); | ||
|
||
response.Dump(); | ||
|
||
var config = client.Config as OAuthConfig; | ||
config.AccessToken.Should().Be("aaa"); | ||
config.RefreshToken.Should().Be("bbb"); | ||
|
||
Examples.UserModel.Should().BeEquivalentTo(response.Data); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters