so dll libary and clr.ahk are needed.
file download link.
https blogattach.naver.com /5cc940f0e2b ... nt.dll.zip Broken Link for safety
* modified. te file is uploaded.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Include %A_ScriptDir%\lib\clr.ahk
; Example Scope
scopes := ["https www.googleapis.com /auth/spreadsheets"] Broken Link for safety
; Use your key file.
filePath := "service.json"
Token := new GoogleAuthWithServiceAccount(filePath, scopes)
Return
class GoogleAuthWithServiceAccount
{
__New(KeyfilePath, scopes)
{
this.filePath := KeyfilePath
this.scopes := scopes
this.check_validation()
dll_path := A_ScriptDir . "\lib\google_api_with_service_token.dll"
asm := CLR_LoadLibrary(dll_path)
this.instance := asm.CreateInstance("google_api_with_service_token.google_api")
arr := ComObjArray(8, scopes.MaxIndex()) ; make safe Array
for k, v in this.scopes
{
arr[k-1] := v ; put the values
}
return this.instance.GetAccessTokenFromJSONKey(this.filePath, arr)
}
check_validation()
{
if(this.filePath = "")
{
throw Exception("There is no filePath.")
}
if !FileExist(this.filePath)
throw Exception("There is no service token file.")
SplitPath,% this.filePath, fileName, OutDir, Ext
if (Ext != "json")
throw Exception("Service Key's extension is maybe json."
+ " please check the valid filePath.")
if(this.scopes.MaxIndex()=0)
{
if (this.scopes="")
throw Exception("There is no scopes.")
}
if(StrLen(this.scopes) > 0)
throw Exception("Scopes have to be array. Not string.")
if(not this.scopes[1])
throw Exception("Scope value is invalid. Please check that.")
}
}
But, there is no sutiable library for rsa encryption. So i have to make the new one. but that is very hard way. so i made dll using 3rd partition.
And below is the c# code in the dll.
No harmful.
Code: Select all
using Google.Apis.Auth.OAuth2;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace google_api_with_service_token
{
class google_api
{
public static async Task<string> GetAccessTokenFromJSONKeyAsync(string jsonKeyFilePath, params string[] scopes)
{
using (var stream = new FileStream(jsonKeyFilePath, FileMode.Open, FileAccess.Read))
{
return await GoogleCredential
.FromStream(stream) // Loads key file
.CreateScoped(scopes) // Gathers scopes requested
.UnderlyingCredential // Gets the credentials
.GetAccessTokenForRequestAsync(); // Gets the Access Token
}
}
public string GetAccessTokenFromJSONKey(string jsonKeyFilePath, params string[] scopes)
{
return GetAccessTokenFromJSONKeyAsync(jsonKeyFilePath, scopes).Result;
}
public void testStringMessage(string msg)
{
MessageBox.Show(msg);
}
public void testStringListMessage(string[] msgs)
{
MessageBox.Show(msgs[0]);
}
}
}