Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Minecraft API with Powershell.
- .DESCRIPTION
- This script allows you to interact with Minecraft accounts via its API with Powershell.
- .NOTES
- Testing.
- .EXAMPLE
- Import-Module .\mcapi.psm1
- New-MCQuery "GET" "/profile"
- .LINK
- https://wiki.vg
- #>
- $Global:MinecraftToken = $null
- Function New-MCQuery([switch]$HideOutput, $RestMethod, $Query, $Arguments, $Data)
- {
- <#
- .SYNOPSIS
- Send a rest query and display the result
- #>
- $URL = "https://api.minecraftservices.com/minecraft" + $Query + $Arguments
- If($Data -eq $null)
- {
- $response = Invoke-RestMethod -Uri $URL -Method $RestMethod -Headers @{ 'Authorization' = "Bearer $Global:MinecraftToken" }
- }
- Else
- {
- $response = Invoke-RestMethod -Uri $URL -Method $RestMethod -Headers @{ 'Authorization' = "Bearer $Global:MinecraftToken" } -Body $json -ContentType 'application/json'
- }
- $response | ConvertTo-Json
- }
- Function Get-MCToken()
- {
- <#
- .SYNOPSIS
- Get API token to build queries afterwards
- #>
- $Credential = $host.ui.PromptForCredential("Need credentials", "Please enter your Minecraft user name and password.", "", "Minecraft")
- $agent = @{
- "name"="Minecraft"
- "version"=1
- }
- $getToken = @{
- "username"=$Credential.UserName
- "password"=$Credential.GetNetworkCredential().Password
- }
- $getToken.Add("agent",$agent)
- $json = $getToken | ConvertTo-Json
- $response = Invoke-RestMethod 'https://authserver.mojang.com/authenticate' -Method 'POST' -Body $json -ContentType 'application/json'
- $Global:MinecraftToken = $response.accessToken
- }
- Get-MCToken
- Export-ModuleMember -Function *
Add Comment
Please, Sign In to add comment