godo icon indicating copy to clipboard operation
godo copied to clipboard

Method to delete an authorized application?

Open csandanov opened this issue 6 years ago • 3 comments

I have an app integration with DigitalOcean and when a user deletes the integration on my app I want to delete it on DigitalOcean. As I understand this could be achieved via https://developers.digitalocean.com/documentation/oauth/#revoke-token-flow, right? Currently as I understand there's no such method in the sdk.

csandanov avatar Feb 21 '20 06:02 csandanov

Hi @csandanov ! Thanks for your report, happy to take a look to see if there's a workaround for this or if it's possible to make it happen soon :)

Verolop avatar Feb 21 '20 17:02 Verolop

Any updates?

csandanov avatar Jun 17 '21 14:06 csandanov

Hey @csandanov,

The SDK does not currently support revoking Oauth tokens. It's something we may add in the future, but there are still some questions around how we want to approach it. In the meantime, here's a quick Go example for revoking a DigitalOcean Oauth token for anyone landing here:

package main

import (
	"log"
	"net/url"

	"golang.org/x/oauth2"
)

const (
	revokeUrl = "https://cloud.digitalocean.com/v1/oauth/revoke"
)

func main() {
	token := "theoauthtokenhere"
	tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
	client := oauth2.NewClient(oauth2.NoContext, tokenSource)

	params := url.Values{}
	params.Set("token", token)
	resp, err := client.PostForm(revokeUrl, params)
	if err != nil {
		log.Fatalf("Error revoking token: %s", err.Error())
	}
	log.Printf("Response status: %s", resp.Status)
}

andrewsomething avatar Jun 21 '21 16:06 andrewsomething