8 changed files with 127 additions and 64 deletions
@ -1,58 +0,0 @@ |
|||
# https://www.deviantart.com/team/status-update/An-adjustments-being-made-to-1307747979 |
|||
|
|||
# Start listiner to copy code from URL |
|||
$Listener = [System.Net.HttpListener]::new() |
|||
# With "/" |
|||
$Listener.Prefixes.Add('http://localhost:8080/cb/') |
|||
$Listener.Start() |
|||
|
|||
$Bytes = [byte[]]::new(32) |
|||
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($Bytes) |
|||
$codeVerifier = [Convert]::ToBase64String($Bytes).TrimEnd('=').Replace('+','-').Replace('/','_') |
|||
$Hash = [System.Security.Cryptography.SHA256]::Create().ComputeHash([Text.Encoding]::ASCII.GetBytes($CodeVerifier)) |
|||
$CodeChallenge = [Convert]::ToBase64String($Hash).TrimEnd('=').Replace('+','-').Replace('/','_') |
|||
$state = [guid]::NewGuid().ToString('N') |
|||
$ClientId = $env:DEVIANTART_CLIENT_ID |
|||
$RedirectURL = [uri]::EscapeDataString("http://localhost:8080/cb") |
|||
Start-Process -FilePath "https://www.deviantart.com/oauth2/authorize?response_type=code&client_id=$clientId&redirect_uri=$RedirectURL&scope=browse&state=$State&code_challenge=$CodeChallenge&code_challenge_method=S256" |
|||
|
|||
# Blocks until the browser hits the redirect_uri |
|||
$context = $Listener.GetContext() |
|||
$request = $context.Request |
|||
$code = $request.QueryString['code'] |
|||
$context.Response.Close() |
|||
$Listener.Stop() |
|||
|
|||
# Get access token |
|||
# https://deviantart.readme.io/docs/authentication |
|||
$Body = @{ |
|||
grant_type = "authorization_code" |
|||
client_id = $env:DEVIANTART_CLIENT_ID |
|||
client_secret = $env:DEVIANTART_CLIENT_SECRET |
|||
redirect_uri = "http://localhost:8080/cb" |
|||
code = $code |
|||
code_verifier = $codeVerifier |
|||
} |
|||
$Parameters = @{ |
|||
Uri = "https://www.deviantart.com/oauth2/token" |
|||
Body = $Body |
|||
Method = "Post" |
|||
Verbose = $true |
|||
UseBasicParsing = $true |
|||
} |
|||
$Response = Invoke-RestMethod @Parameters |
|||
|
|||
# Get download URL |
|||
# UUID is 8A8DC033-242C-DD2E-EDB0-CC864772D5F4 |
|||
# https://www.deviantart.com/jepricreations/art/Windows-11-Cursors-Concept-886489356 |
|||
$Headers = @{ |
|||
Authorization = "Bearer $($Response.access_token)" |
|||
} |
|||
$Parameters = @{ |
|||
Uri = "https://www.deviantart.com/api/v1/oauth2/deviation/download/8A8DC033-242C-DD2E-EDB0-CC864772D5F4?mature_content=true" |
|||
Headers = $Headers |
|||
Verbose = $true |
|||
UseBasicParsing = $true |
|||
} |
|||
$Response = Invoke-RestMethod @Parameters |
|||
$Response.src |
|||
@ -1,7 +1,7 @@ |
|||
# https://www.deviantart.com/jepricreations/art/Windows-11-Cursors-Concept-886489356 |
|||
# https://jepricreations.com/products/w11-cursor-concept-free |
|||
|
|||
# We cannot download archive using Deviant Art's API due to limitations as it requires a human interection |
|||
# We cannot automate downlaoding archive using Deviant Art's API due to limitations as it requires a human interection |
|||
# https://www.deviantart.com/team/status-update/An-adjustments-being-made-to-1307747979 |
|||
|
|||
Get-Process -Name msedgedriver, msedge -ErrorAction Ignore | Stop-Process -Force -ErrorAction Ignore |
|||
@ -0,0 +1,56 @@ |
|||
# https://www.deviantart.com/team/status-update/An-adjustments-being-made-to-1307747979 |
|||
|
|||
# Get access token |
|||
# https://www.deviantart.com/developers/authentication |
|||
$Body = @{ |
|||
grant_type = "refresh_token" |
|||
client_id = $env:DEVIANTART_CLIENT_ID |
|||
client_secret = $env:DEVIANTART_CLIENT_SECRET |
|||
refresh_token = $env:DEVIANTART_TOKEN |
|||
} |
|||
$Parameters = @{ |
|||
Uri = "https://www.deviantart.com/oauth2/token" |
|||
Body = $Body |
|||
Method = "Post" |
|||
Verbose = $true |
|||
UseBasicParsing = $true |
|||
} |
|||
$Token = Invoke-RestMethod @Parameters |
|||
|
|||
# Hide tokens in the workflow log |
|||
Write-Output -InputObject "::add-mask::$($Token.access_token)" |
|||
Write-Output -InputObject "::add-mask::$($Token.refresh_token)" |
|||
|
|||
# A new refresh token is issued on every refresh and the previous one stops working, so save the new one for the next run before doing anything else |
|||
# GITHUB_TOKEN cannot write secrets, so GH_TOKEN has to be a personal access token with the "Secrets: Read and write" permission |
|||
gh secret set DEVIANTART_TOKEN --body $Token.refresh_token --repo $env:GITHUB_REPOSITORY |
|||
|
|||
# Get download URL |
|||
# UUID is 8A8DC033-242C-DD2E-EDB0-CC864772D5F4 |
|||
# https://www.deviantart.com/jepricreations/art/Windows-11-Cursors-Concept-886489356 |
|||
$Headers = @{ |
|||
Authorization = "Bearer $($Token.access_token)" |
|||
} |
|||
$Parameters = @{ |
|||
Uri = "https://www.deviantart.com/api/v1/oauth2/deviation/download/8A8DC033-242C-DD2E-EDB0-CC864772D5F4?mature_content=true" |
|||
Headers = $Headers |
|||
Verbose = $true |
|||
UseBasicParsing = $true |
|||
} |
|||
$Response = Invoke-RestMethod @Parameters |
|||
|
|||
# Download the archive to a temp folder first to not overwrite the valid one in the repo with a broken download |
|||
$Parameters = @{ |
|||
Uri = $Response.src |
|||
OutFile = "$env:RUNNER_TEMP\w11-cursor-concept-free.zip" |
|||
UseBasicParsing = $true |
|||
Verbose = $true |
|||
} |
|||
Invoke-WebRequest @Parameters |
|||
|
|||
$Parameters = @{ |
|||
Path = "$env:RUNNER_TEMP\w11-cursor-concept-free.zip" |
|||
Destination = "Cursors\w11-cursor-concept-free.zip" |
|||
Force = $true |
|||
} |
|||
Move-Item @Parameters |
|||
@ -0,0 +1,61 @@ |
|||
# Run once locally to sign in to DeviantArt in a browser and get a refresh token for CI/CD |
|||
# https://www.deviantart.com/studio/apps |
|||
|
|||
$client_id = "" |
|||
$client_secret = "" |
|||
|
|||
$Bytes = [byte[]]::new(32) |
|||
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($Bytes) |
|||
$CodeVerifier = [Convert]::ToBase64String($Bytes).TrimEnd("=").Replace("+", "-").Replace("/", "_") |
|||
$Hash = [System.Security.Cryptography.SHA256]::Create().ComputeHash([Text.Encoding]::ASCII.GetBytes($CodeVerifier)) |
|||
$CodeChallenge = [Convert]::ToBase64String($Hash).TrimEnd("=").Replace("+", "-").Replace("/", "_") |
|||
$State = [guid]::NewGuid().ToString("N") |
|||
$RedirectURL = [uri]::EscapeDataString("http://localhost:8080/cb") |
|||
|
|||
# Start listener to get code from redirect URL |
|||
$Listener = [System.Net.HttpListener]::new() |
|||
# With "/" |
|||
$Listener.Prefixes.Add("http://localhost:8080/cb/") |
|||
|
|||
try |
|||
{ |
|||
$Listener.Start() |
|||
|
|||
Start-Process -FilePath "https://www.deviantart.com/oauth2/authorize?response_type=code&client_id=$client_id&redirect_uri=$RedirectURL&scope=browse&state=$State&code_challenge=$CodeChallenge&code_challenge_method=S256" |
|||
|
|||
# Blocks until the browser hits the redirect_uri |
|||
$Context = $Listener.GetContext() |
|||
$Code = $Context.Request.QueryString["code"] |
|||
$ReturnedState = $Context.Request.QueryString["state"] |
|||
|
|||
$Buffer = [Text.Encoding]::UTF8.GetBytes("Done. You can close this tab.") |
|||
$Context.Response.OutputStream.Write($Buffer, 0, $Buffer.Length) |
|||
$Context.Response.Close() |
|||
} |
|||
finally |
|||
{ |
|||
# Release http://localhost:8080/cb/ even if the script failed or was interrupted |
|||
$Listener.Close() |
|||
} |
|||
|
|||
$Body = @{ |
|||
grant_type = "authorization_code" |
|||
client_id = $client_id |
|||
client_secret = $client_secret |
|||
redirect_uri = "http://localhost:8080/cb" |
|||
code = $Code |
|||
code_verifier = $CodeVerifier |
|||
} |
|||
$Parameters = @{ |
|||
Uri = "https://www.deviantart.com/oauth2/token" |
|||
Body = $Body |
|||
Method = "Post" |
|||
Verbose = $true |
|||
UseBasicParsing = $true |
|||
} |
|||
$Token = Invoke-RestMethod @Parameters |
|||
|
|||
$Token.refresh_token |
|||
|
|||
Set-Clipboard -Value $Token.refresh_token |
|||
Start-Process -FilePath "https://github.com/farag2/Sophia-Script-for-Windows/settings/secrets/actions/DEVIANTART_TOKEN" |
|||
Loading…
Reference in new issue