Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OAuth Token operations to new APIs #2116

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Octokit.Tests/Clients/AuthorizationsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ public async Task ChecksApplicationAuthenticateAtCorrectUrl()

authEndpoint.CheckApplicationAuthentication("clientId", "accessToken");

client.Received().Get<ApplicationAuthorization>(
Arg.Is<Uri>(u => u.ToString() == "applications/clientId/tokens/accessToken"),
null);
client.Received().Post<ApplicationAuthorization>(
Arg.Is<Uri>(u => u.ToString() == "applications/clientId/token"),
Args.Object);
shiftkey marked this conversation as resolved.
Show resolved Hide resolved
}

[Fact]
Expand All @@ -318,8 +318,8 @@ public async Task ResetsApplicationAuthenticationAtCorrectUrl()

authEndpoint.ResetApplicationAuthentication("clientId", "accessToken");

client.Received().Post<ApplicationAuthorization>(
Arg.Is<Uri>(u => u.ToString() == "applications/clientId/tokens/accessToken"),
client.Received().Patch<ApplicationAuthorization>(
Arg.Is<Uri>(u => u.ToString() == "applications/clientId/token"),
Args.Object);
}

Expand Down Expand Up @@ -347,7 +347,8 @@ public async Task RevokesApplicationAuthenticationAtCorrectUrl()
authEndpoint.RevokeApplicationAuthentication("clientId", "accessToken");

client.Received().Delete(
Arg.Is<Uri>(u => u.ToString() == "applications/clientId/tokens/accessToken"));
Arg.Is<Uri>(u => u.ToString() == "applications/clientId/token"),
Args.Object);
}

[Fact]
Expand Down
26 changes: 20 additions & 6 deletions Octokit/Clients/AuthorizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,13 @@ public Task<ApplicationAuthorization> CheckApplicationAuthentication(string clie
Ensure.ArgumentNotNullOrEmptyString(clientId, nameof(clientId));
Ensure.ArgumentNotNullOrEmptyString(accessToken, nameof(accessToken));

var endpoint = ApiUrls.ApplicationAuthorization(clientId, accessToken);
return ApiConnection.Get<ApplicationAuthorization>(endpoint, null);
var requestData = new
{
access_token = accessToken
};

var endpoint = ApiUrls.ApplicationAuthorization(clientId);
return ApiConnection.Post<ApplicationAuthorization>(endpoint, requestData);
}

/// <summary>
Expand All @@ -360,9 +365,13 @@ public Task<ApplicationAuthorization> ResetApplicationAuthentication(string clie
Ensure.ArgumentNotNullOrEmptyString(clientId, nameof(clientId));
Ensure.ArgumentNotNullOrEmptyString(accessToken, nameof(accessToken));

var requestData = new { };
var requestData = new
{
access_token = accessToken
};

return ApiConnection.Post<ApplicationAuthorization>(ApiUrls.ApplicationAuthorization(clientId, accessToken), requestData);
var endpoint = ApiUrls.ApplicationAuthorization(clientId);
return ApiConnection.Patch<ApplicationAuthorization>(endpoint, requestData);
}

/// <summary>
Expand All @@ -380,8 +389,13 @@ public Task RevokeApplicationAuthentication(string clientId, string accessToken)
Ensure.ArgumentNotNullOrEmptyString(clientId, nameof(clientId));
Ensure.ArgumentNotNullOrEmptyString(accessToken, nameof(accessToken));

return ApiConnection.Delete(
ApiUrls.ApplicationAuthorization(clientId, accessToken));
var requestData = new
{
access_token = accessToken
};

var endpoint = ApiUrls.ApplicationAuthorization(clientId);
return ApiConnection.Delete(endpoint, requestData);
}

/// <summary>
Expand Down
7 changes: 1 addition & 6 deletions Octokit/Helpers/ApiUrls.Authorizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ public static Uri AuthorizationsForClient(string clientId)

public static Uri ApplicationAuthorization(string clientId)
{
return "applications/{0}/tokens".FormatUri(clientId);
}

public static Uri ApplicationAuthorization(string clientId, string accessToken)
{
return "applications/{0}/tokens/{1}".FormatUri(clientId, accessToken);
return "applications/{0}/token".FormatUri(clientId);
}
}
}