wg-gen-web icon indicating copy to clipboard operation
wg-gen-web copied to clipboard

Using the API

Open xiki808 opened this issue 4 years ago • 6 comments

Can I make use of your API externally?

So for example how can I get a response from: http:///api/v1.0/server/version?

I'm always getting a 401 Unauthorized error.

xiki808 avatar Nov 26 '20 21:11 xiki808

are you using OAuth2 OIDC ? if yes you need to provide access token in x-wg-gen-web-auth header after authentication

vx3r avatar Nov 29 '20 20:11 vx3r

No I'm not, do I need to to access the API? I will check more about this, this evening.

xiki808 avatar Nov 30 '20 16:11 xiki808

HOw can we not re-generate this token on every login? or maybe assign a key in docker-compose? Thanks

jerry3k avatar Dec 10 '20 19:12 jerry3k

How can I create an access token? Can someone guide me please?

I'm sending this: URL: /api/v1.0/auth/oauth2_url Return:

{
    "oauth2": true,
    "clientId": "674zPDl44mbPRaF-6x4q0aHBl0ebAP7zyznOj8PNcu8=",
    "code": "",
    "state": "70etxPg9TBraUhrAdaYxBlJ8CDwZKBcB6DL-c3ziG9k=",
    "codeUrl": "_magic_string_fake_auth_no_redirect_"
}

And then send: Url: /api/v1.0/auth/oauth2_exchange Body:

{
	"clientid": "674zPDl44mbPRaF-6x4q0aHBl0ebAP7zyznOj8PNcu8==",
	"code": "",
	"state": "70etxPg9TBraUhrAdaYxBlJ8CDwZKBcB6DL-c3ziG9k="
}

and it returns 400 bad request.

I am not setting any authentication but opting to use fake Oauth. The console logs this:

wireguard-webui    | [GIN] 2020/12/11 - 22:30:29 | 400 |     209.417µs |   192.168.1.211 | POST     "/api/v1.0/auth/oauth2_exchange"
wireguard-webui    | time="2020-12-11T22:30:29Z" level=error msg="saved state and client provided state mismatch" savedState="<nil>" state="70etxPg9TBraUhrAdaYxBlJ8CDwZKBcB6DL-c3ziG9k="

xiki808 avatar Dec 11 '20 22:12 xiki808

I changed from using Postman to Insomnia to test requests, and I didn't have the problem anymore.

xiki808 avatar Dec 12 '20 09:12 xiki808

Did you manage to connect via api using access token. My token is updated every ~15 minutes. And when I generate my tokens, they don't fit here

andrew3203 avatar May 07 '22 17:05 andrew3203