This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #239 from aspriddell/update-roles
Update roles
- Loading branch information
Showing
7 changed files
with
45 additions
and
105 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 was deleted.
Oops, something went wrong.
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
35 changes: 2 additions & 33 deletions
35
DragonFruit.Six.Api/Services/Developer/Dragon6DeveloperClient.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,18 @@ | ||
// Dragon6 API Copyright 2020 DragonFruit Network <inbox@dragonfruit.network> | ||
// Licensed under Apache-2. Please refer to the LICENSE file for more info | ||
|
||
using DragonFruit.Common.Data.Extensions; | ||
using DragonFruit.Six.Api.Tokens; | ||
using DragonFruit.Six.Api.Services.Developer.Auth; | ||
|
||
namespace DragonFruit.Six.Api.Services.Developer | ||
{ | ||
public class Dragon6DeveloperClient : Dragon6Client | ||
{ | ||
private readonly uint _appId; | ||
private readonly string _appSecret; | ||
private readonly object _lock; | ||
|
||
private TokenBase _sessionAuthorization; | ||
|
||
public Dragon6DeveloperClient(uint appId, string appSecret) | ||
public Dragon6DeveloperClient(string key) | ||
{ | ||
_appId = appId; | ||
_appSecret = appSecret; | ||
|
||
_lock = new object(); | ||
} | ||
|
||
public T Perform<T>(DeveloperApiRequest requestData) where T : class | ||
{ | ||
lock (_lock) | ||
{ | ||
CheckAuthHeader(requestData); | ||
} | ||
|
||
return DirectPerform<T>(requestData); | ||
Authorization = $"Dragon6-Api {key}"; | ||
} | ||
|
||
protected override TokenBase GetToken() => Perform<Dragon6Token>(new DeveloperTokenRequest()); | ||
|
||
private void CheckAuthHeader(DeveloperApiRequest request) | ||
{ | ||
if ((_sessionAuthorization?.Expired).GetValueOrDefault(true)) | ||
{ | ||
// we don't want this method running if we're getting the token so use the directperform method | ||
_sessionAuthorization = DirectPerform<DeveloperTokenResponse>(new DeveloperSessionRequest(_appId, _appSecret)); | ||
} | ||
|
||
request.WithAuthHeader($"Bearer {_sessionAuthorization!.Token}"); | ||
} | ||
} | ||
} |
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