Endbenutzerauthentifizierung mit OAuth Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

effel
Posts: 555
Joined: 16 Jan 2018, 13:34

Endbenutzerauthentifizierung mit OAuth

Post by effel » 23 Dec 2023, 05:04

Hallo, kann mir bitte jemand zeigen wie ich den Java Code für AHK nutze um den Token zu erzeugen?


https://www.meteomatics.com/en/api/request/api-requests-oauth-authentification/

Code: Select all

username='yourUsername'
password='ABCDeij953ad'
let headers = new Headers();
headers.set('Authorization', 'Basic ' + btoa(username + ":" + password));

fetch('https://login.meteomatics.com/api/v1/token', {
    method: 'GET', headers: headers
}).then(function (resp) {
    return resp.json();
}).then(function (data) {
    var token = data.access_token;
    console.log('token', token);
}).catch(function (err) {
    console.log('something went wrong', err);
});

KHA
Posts: 408
Joined: 21 Aug 2018, 11:11

Re: Endbenutzerauthentifizierung mit OAuth  Topic is solved

Post by KHA » 26 Dec 2023, 14:16

Wenn ich das richtig verstanden habe:

Code: Select all

#NoEnv
username := "xxx"
password := "xxx"

auth := username . ":" . password
Base64encUTF8(authenc, auth )

objHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
url := "https://login.meteomatics.com/api/v1/token"
objHTTP.Open("GET", url, false)
objHTTP.SetRequestHeader("Authorization", "Basic " . authenc)
objHTTP.Send()
if (objHTTP.Status = 200) {
    MsgBox, % "Token: " . objHTTP.ResponseText
} else {
    MsgBox, % "Error: " . objHTTP.Status . "`n" . objHTTP.ResponseText
}


Base64encUTF8( ByRef OutData, ByRef InData )
{ ; by SKAN + my modifications to encode to UTF-8
  InDataLen := StrPutVar(InData, InData, "UTF-8") - 1
  DllCall( "Crypt32.dll\CryptBinaryToStringW", UInt,&InData, UInt,InDataLen, UInt,1, UInt,0, UIntP,TChars, "CDECL Int" )
  VarSetCapacity( OutData, Req := TChars * ( A_IsUnicode ? 2 : 1 ), 0 )
  DllCall( "Crypt32.dll\CryptBinaryToStringW", UInt,&InData, UInt,InDataLen, UInt,1, Str,OutData, UIntP,Req, "CDECL Int" )
  Return TChars
}

StrPutVar(string, ByRef var, encoding)
{
    ; Ensure capacity.
    VarSetCapacity( var, StrPut(string, encoding)
        ; StrPut returns char count, but VarSetCapacity needs bytes.
        * ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
    ; Copy or convert the string.
    return StrPut(string, &var, encoding)
}

effel
Posts: 555
Joined: 16 Jan 2018, 13:34

Re: Endbenutzerauthentifizierung mit OAuth

Post by effel » 27 Dec 2023, 17:50

@KHA vielen Dank für deine Mühe, das funktioniert wie gedacht

Post Reply

Return to “Ich brauche Hilfe”