Skip to content

Commit 0dcc455

Browse files
authored
Merge pull request #35 from umbraco/feature/testing-0.3
Add test services endpoints
2 parents 2795e28 + e952932 commit 0dcc455

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

examples/Umbraco.AuthorizedServices.TestSite/Controllers/TestAuthorizedServicesController.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ public async Task<IActionResult> GetAssetsFromAssetBank(string assetIds)
138138
return Content(string.Join(", ", response.Select(x => x.ToString())));
139139
}
140140

141-
public async Task<IActionResult> GetVideoDetailsFromYouTube()
141+
public async Task<IActionResult> GetVideoDetailsFromYouTube(string videoId)
142142
{
143143
Attempt<string?> responseAttempt = await AuthorizedServiceCaller.SendRequestRawAsync(
144144
"youtube",
145-
"/v3/videos?id=[video_id]&part=snippet,contentDetails,statistics,status",
145+
$"/v3/videos?id={videoId}&part=snippet,contentDetails,statistics,status",
146146
HttpMethod.Get);
147147

148148
if (!responseAttempt.Success || responseAttempt.Result is null)
@@ -154,6 +154,52 @@ public async Task<IActionResult> GetVideoDetailsFromYouTube()
154154
return Content(response);
155155
}
156156

157+
public async Task<IActionResult> GetInstagramProfile()
158+
{
159+
Attempt<InstagramProfileResponse?> responseAttempt = await AuthorizedServiceCaller.GetRequestAsync<InstagramProfileResponse>(
160+
"instagram",
161+
$"/v3.0/me?fields=username");
162+
163+
if (!responseAttempt.Success || responseAttempt.Result is null)
164+
{
165+
return HandleFailedRequest(responseAttempt.Exception, "Could not retrieve account details.");
166+
}
167+
168+
return Content(responseAttempt.Result.Username);
169+
}
170+
171+
public async Task<IActionResult> GetTwitterProfileUsingOAuth1()
172+
{
173+
Attempt<string?> responseAttempt = await AuthorizedServiceCaller.SendRequestRawAsync(
174+
"twitter",
175+
"/1.1/account/settings.json",
176+
HttpMethod.Get);
177+
178+
if (!responseAttempt.Success || responseAttempt.Result is null)
179+
{
180+
return HandleFailedRequest(responseAttempt.Exception, "Could not retrieve account details.");
181+
}
182+
183+
var response = responseAttempt.Result;
184+
return Content(response);
185+
}
186+
187+
public async Task<IActionResult> GetTwitterProfileUsingOAuth2()
188+
{
189+
Attempt<string?> responseAttempt = await AuthorizedServiceCaller.SendRequestRawAsync(
190+
"twitter_oauth2",
191+
"/2/users/me",
192+
HttpMethod.Get);
193+
194+
if (!responseAttempt.Success || responseAttempt.Result is null)
195+
{
196+
return HandleFailedRequest(responseAttempt.Exception, "Could not retrieve account details.");
197+
}
198+
199+
var response = responseAttempt.Result;
200+
return Content(response);
201+
}
202+
157203
public IActionResult GetApiKey(string serviceAlias)
158204
{
159205
Attempt<string?> apiKeyAttempt = AuthorizedServiceCaller.GetApiKey(serviceAlias);

examples/Umbraco.AuthorizedServices.TestSite/appsettings.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@
154154
"Scopes": "r_emailaddress r_liteprofile w_member_social",
155155
"SampleRequest": "/v2/me"
156156
},
157-
"twitter-oauth2": {
157+
"twitter_oauth2": {
158158
"DisplayName": "Twitter OAuth2",
159-
"AuthenticationMethod": "OAuth2Code",
160159
"ApiHost": "https://api.twitter.com",
161160
"IdentityHost": "https://twitter.com",
162161
"TokenHost": "https://api.twitter.com",
@@ -508,7 +507,7 @@
508507
},
509508
"instagram": {
510509
"DisplayName": "Instagram",
511-
"ApiHost": "https://api.instagram.com",
510+
"ApiHost": "https://graph.instagram.com",
512511
"IdentityHost": "https://api.instagram.com",
513512
"TokenHost": "https://api.instagram.com",
514513
"RequestIdentityPath": "/oauth/authorize",

src/Umbraco.AuthorizedServices/ClientApp/src/backoffice/AuthorizedServices/edit.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function AuthorizedServiceEditController(this: any, $routeParams, $location, aut
3737
notificationsService.success("Authorized Services", "The '" + vm.displayName + "' service has been authorized.");
3838
loadServiceDetails(serviceAlias);
3939
});
40-
} if (vm.authenticationMethod.isOAuth1) {
40+
} else if (vm.authenticationMethod.isOAuth1) {
4141
authorizedServiceResource.generateOAuth1RequestToken(serviceAlias)
4242
.then(function (response) {
4343
location.href = response.data.message;

src/Umbraco.AuthorizedServices/ClientApp/src/backoffice/AuthorizedServices/edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</div>
3737
</div>
3838
</div>
39-
<div ng-show="!vm.isAuthorized">
39+
<div ng-show="!vm.isAuthorized && !vm.authenticationMethod.isApiKey">
4040
<p>To authorize the service click to sign-in to the provider's portal, confirm the permission request and return to Umbraco.</p>
4141
<umb-button action="vm.authorizeAccess()"
4242
type="button"

0 commit comments

Comments
 (0)