-
Notifications
You must be signed in to change notification settings - Fork 7
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 #20 from markekraus/develop
Add Token Update Capabilities Documentation errors will be fixed in this branch. Works towards #8 #11 #12
- Loading branch information
Showing
14 changed files
with
1,134 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<# | ||
.NOTES | ||
Created with: VSCode | ||
Created on: 5/17/2017 03:58 PM | ||
Editied on: 5/18/2017 | ||
Created by: Mark Kraus | ||
Organization: | ||
Filename: Request-RedditOAuthTokenRefresh.ps1 | ||
.DESCRIPTION | ||
Request-RedditOAuthTokenRefresh Function | ||
#> | ||
[CmdletBinding()] | ||
param() | ||
|
||
function Request-RedditOAuthTokenRefresh { | ||
[CmdletBinding( | ||
HelpUri = 'https://psraw.readthedocs.io/en/latest/PrivateFunctions/Request-RedditOAuthTokenRefresh' | ||
)] | ||
[OutputType([Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject])] | ||
param ( | ||
[Parameter( | ||
mandatory = $true, | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true | ||
)] | ||
[ValidateScript( | ||
{ | ||
If (-not ($_.GrantType -eq [RedditOAuthGrantType]::Authorization_Code )) { | ||
$Exception = [System.Management.Automation.ValidationMetadataException]::new( | ||
"RedditOAuthToken must be of RedditOAuthGrantType 'Authorization_Code'" | ||
) | ||
Throw $Exception | ||
} | ||
$true | ||
} | ||
)] | ||
[Alias('Token')] | ||
[RedditOAuthToken]$AccessToken, | ||
|
||
[Parameter( | ||
mandatory = $false, | ||
ValueFromPipeline = $false, | ||
ValueFromPipelineByPropertyName = $false | ||
)] | ||
[String]$AuthBaseUrl = [RedditOAuthToken]::AuthBaseURL | ||
) | ||
process { | ||
$Params = @{ | ||
Uri = $AuthBaseUrl | ||
Body = @{ | ||
grant_type = 'refresh_token' | ||
refresh_token = $AccessToken.GetRefreshToken() | ||
} | ||
UserAgent = $AccessToken.Application.UserAgent | ||
Headers = @{ | ||
Authorization = $AccessToken.Application.ClientCredential | Get-AuthorizationHeader | ||
} | ||
Method = 'POST' | ||
UseBasicParsing = $true | ||
} | ||
Invoke-WebRequest @Params | ||
} | ||
} |
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,92 @@ | ||
<# | ||
.NOTES | ||
Created with: VSCode | ||
Created on: 5/17/2017 04:07 AM | ||
Editied on: 5/18/2017 | ||
Created by: Mark Kraus | ||
Organization: | ||
Filename: Update-RedditOAuthToken.ps1 | ||
.DESCRIPTION | ||
Update-RedditOAuthToken Function | ||
#> | ||
[CmdletBinding()] | ||
param() | ||
|
||
function Update-RedditOAuthToken { | ||
[CmdletBinding( | ||
HelpUri = 'https://psraw.readthedocs.io/en/latest/Module/Update-RedditOAuthToken', | ||
SupportsShouldProcess = $true | ||
)] | ||
[OutputType([RedditOAuthToken])] | ||
param | ||
( | ||
[Parameter( | ||
Mandatory = $true, | ||
ValueFromPipeline = $true, | ||
ValueFromPipelineByPropertyName = $true, | ||
Position = 0 | ||
)] | ||
[Alias('Token')] | ||
[RedditOAuthToken[]]$AccessToken, | ||
|
||
[switch]$Force, | ||
|
||
[switch]$PassThru | ||
|
||
) | ||
|
||
process { | ||
foreach ($Token in $AccessToken) { | ||
if (-not $PSCmdlet.ShouldProcess($Token.GUID)) { | ||
continue | ||
} | ||
if (-not $Token.IsExpired() -and -not $Force) { | ||
continue | ||
} | ||
switch ($Token.GrantType) { | ||
'Installed_Client' { | ||
$Params = @{ | ||
Application = $Token.Application | ||
DeviceID = $Token.DeviceID | ||
} | ||
$Result = Request-RedditOAuthTokenInstalled @Params | ||
Break | ||
} | ||
'Authorization_Code' { | ||
$Params = @{ | ||
AccessToken = $Token | ||
} | ||
$Result = Request-RedditOAuthTokenRefresh @Params | ||
Break | ||
} | ||
'Password' { | ||
$Params = @{ | ||
Application = $Token.Application | ||
} | ||
$Result = Request-RedditOAuthTokenPassword @Params | ||
Break | ||
} | ||
'Client_Credentials' { | ||
$Params = @{ | ||
Application = $Token.Application | ||
} | ||
$Result = Request-RedditOAuthTokenClient @Params | ||
Break | ||
} | ||
'Implicit' { | ||
$Params = @{ | ||
Application = $Token.Application | ||
} | ||
$Result = Request-RedditOAuthTokenImplicit @Params | ||
Break | ||
} | ||
} | ||
$Token.Refresh($Result) | ||
if ($PassThru.IsPresent) { | ||
$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
Oops, something went wrong.