Zum Hauptinhalt springen

Überblick

AdGuard DNS bietet eine REST-API, die Sie zur Integration Ihrer Anwendungen verwenden können.

Authentifizierung

Zugriffstoken generieren

Stellen Sie eine POST-Anfrage für die folgende URL mit den angegebenen Parametern, um den access_token zu erzeugen:

https://api.adguard-dns.io/oapi/v1/oauth_token

ParameterBeschreibung
usernameAccount email
passwordAccount password
mfa_tokenToken für die Zwei-Faktor-Authentifizierung (falls in den Kontoeinstellungen aktiviert)

In der Antwort erhalten Sie sowohl den access_token als auch den refresh_token.

  • Der access_token läuft nach einigen angegebenen Sekunden ab (dargestellt durch den expires_in Parameter in der Antwort). You can regenerate a new access_token using the refresh_token (Refer: Generate Access Token from Refresh Token).

  • The refresh_token is permanent. To revoke a refresh_token, refer: Revoking a Refresh Token.

Beispielanfrage

$ curl 'https://api.adguard-dns.io/oapi/v1/oauth_token' -i -X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'username=user%40adguard.com' \
-d 'password=********' \
-d 'mfa_token=727810'

Beispielantwort

{
"access_token": "jTFho_aymtN20pZR5RRSQAzd81I",
"token_type": "bearer",
"refresh_token": "H3SW6YFJ-tOPe0FQCM1Jd6VnMiA",
"expires_in": 2620978
}

Generate Access Token from Refresh Token

Access tokens have limited validity. Once it expires, your app will have to use the refresh token to request for a new access token.

Make the following POST request with the given params to get a new access token:

https://api.adguard-dns.io/oapi/v1/oauth_token

ParameterBeschreibung
refresh_tokenREFRESH TOKEN using which a new access token has to be generated.

Beispielanfrage

$ curl 'https://api.adguard-dns.io/oapi/v1/oauth_token' -i -X POST \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'refresh_token=H3SW6YFJ-tOPe0FQCM1Jd6VnMiA'

Beispielantwort

{
"access_token": "xQnT7GYT6Ag--3oY_EcOOdXe-I0",
"token_type": "bearer",
"refresh_token": "H3SW6YFJ-tOPe0FQCM1Jd6VnMiA",
"expires_in": 2627999
}

Revoking a Refresh Token

To revoke a refresh token, make the following POST request with the given params:

https://api.adguard-dns.io/oapi/v1/revoke_token

Request Example

$ curl 'https://api.adguard-dns.io/oapi/v1/revoke_token' -i -X POST \
-d 'token=H3SW6YFJ-tOPe0FQCM1Jd6VnMiA'
ParameterBeschreibung
refresh_tokenREFRESH TOKEN which is to be revoked

Authorization endpoint

To access this endpoint, you need to contact us at devteam@adguard.com. Please describe the reason and use cases for this endpoint, as well as provide the redirect URI. Upon approval, you will receive a unique client identifier, which should be used for the client_id parameter.

The /oapi/v1/oauth_authorize endpoint is used to interact with the resource owner and get the authorization to access the protected resource.

The service redirects you to AdGuard to authenticate (if you are not already logged in) and then back to your application.

The request parameters of the /oapi/v1/oauth_authorize endpoint are:

ParameterBeschreibung
response_typeTells the authorization server which grant to execute
client_idThe ID of the OAuth client that asks for authorization
redirect_uriContains a URL. A successful response from this endpoint results in a redirect to this URL
stateAn opaque value used for security purposes. If this request parameter is set in the request, it is returned to the application as part of the redirect_uri
aidAffiliate identifier

For example:

https://api.adguard-dns.io/oapi/v1/oauth_authorize?response_type=token&client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&state=1jbmuc0m9WTr1T6dOO82

To inform the authorization server which grant type to use, the response_type request parameter is used as follows:

  • For the Implicit grant, use response_type=token to include an access token.

A successful response is 302 Found, which triggers a redirect to redirect_uri (which is a request parameter). The response parameters are embedded in the fragment component (the part after #) of the redirect_uri parameter in the Location header.

For example:

HTTP/1.1 302 Found
Location: REDIRECT_URI#access_token=...&token_type=Bearer&expires_in=3600&state=1jbmuc0m9WTr1T6dOO82

Accessing API

Once the access and the refresh tokens are generated, API calls can be made by passing the access token in the header.

  • Header name should be Authorization
  • Header value should be Bearer {access_token}

API

Referenz

Bitte lesen Sie die Methodenreferenz hier.

OpenAPI-Spezifikation

Die OpenAPI-Spezifikation ist verfügbar unter https://api.adguard-dns.io/static/swagger/openapi.json.

Sie können verschiedene Methoden verwenden, um die Liste der verfügbaren API-Methoden anzuzeigen. Sie können diese Datei zum Beispiel in https://editor.swagger.io/ öffnen.

Änderungsprotokoll

Das vollständige Änderungsprotokoll der AdGuard DNS-API finden Sie auf dieser Seite.

Feedback

Wenn Sie möchten, dass diese API um neue Methoden erweitert wird, senden Sie uns bitte eine E-Mail an devteam@adguard.com und teilen Sie uns mit, was Sie gerne hinzufügen möchten.