Skip to content

Commit

Permalink
Add oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Sep 3, 2024
1 parent 39a2239 commit 5db26a7
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .emacs.d/.mew.d/oauth2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Mew OAuth2

see https://www.rworks.jp/system/system-column/sys-practice/27806/
26 changes: 26 additions & 0 deletions .emacs.d/.mew.d/oauth2/delegate-auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
print "<!doctype html>\n";
print "<html lang=\"ja\">\n";
print "<head>\n";
print " <meta charset=\"UTF-8\">\n";
print " <title>OAuth2 Authorization コードリクエスト</title>\n";
print "</head>\n";
print "<body>\n";

if ($_GET['p'] != "") {
$url_file = "/tmp/oauth-url." . $_GET['p'];
if (file_exists($url_file)) {
$url = file_get_contents($url_file);
print "<p>以下にアクセスしてください。</p>\n";
print "<a href=\"";
print $url;
print "\">Authorization コードリクエスト</a>\n";
unlink($url_file);
} else {
print "<p>エラー: リクエスト URL を取得できませんでした。もう一度やり直 してください。</p>\n";
}
} else {
print "エラー: リクエストが不正です。\n";
}

print "</body></html>\n";
33 changes: 33 additions & 0 deletions .emacs.d/.mew.d/oauth2/get-auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
$AUTHURL = "https://login.microsoftonline.com/organizations/oauth2/v2.0/authoriz";

print "<html><body>\n";

if ($_GET['error'] == '') {
$code = $_GET['code'];
if ($code == "" ) {
print "エラー: Authorization コードを取得できませんでした。\n";
} else {
print "次の Authorization コードを Emacs にコピーしてください。<br>\n";

print '<input id="copyTarget" type="text" size="120" value="';
print $code;
print '" readonly>';
print '<button onclick="copyToClipboard()">クリップボードにコピー</button>';
print "\n";
}
} else {
print "エラー: 認証できませんでした。\n";
}
print "</body></html>\n";
?>

<script type="text/javascript">

function copyToClipboard() {
var copyTarget = document.getElementById("copyTarget");
copyTarget.select();
document.execCommand("Copy");
alert("コピーしました: " + copyTarget.value);
}
</script>
62 changes: 62 additions & 0 deletions .emacs.d/.mew.d/oauth2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Configure the Azure provider
# see https://learn.microsoft.com/ja-jp/azure/app-service/provision-resource-terraform
terraform {
cloud {
organization = "skirnir"
workspaces {
name = "dotfiles"
}
}
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0.0"
}
}
required_version = ">= 0.14.9"
}
provider "azurerm" {
features {}
}

# Generate a random integer to create a globally unique name
resource "random_integer" "ri" {
min = 10000
max = 99999
}

# Create the resource group
resource "azurerm_resource_group" "rg" {
name = "mew-oauth2"
location = "japaneast"
}

# Create the Linux App Service Plan
resource "azurerm_service_plan" "appserviceplan" {
name = "mew-oauth2"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
os_type = "Linux"
sku_name = "F1"
}

# Create the web app, pass in the App Service Plan ID
resource "azurerm_linux_web_app" "webapp" {
name = "mew-oauth2"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
service_plan_id = azurerm_service_plan.appserviceplan.id
https_only = true
site_config {
minimum_tls_version = "1.2"
}
}

# Deploy code from a public GitHub repo
resource "azurerm_app_service_source_control" "sourcecontrol" {
app_id = azurerm_linux_web_app.webapp.id
repo_url = "https://github.com/nanasess/dotfiles"
branch = "main"
use_manual_integration = true
use_mercurial = false
}
22 changes: 22 additions & 0 deletions .emacs.d/.mew.d/oauth2/request_auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$AUTHURL = "https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize";

print "<html><body>\n";

if ($_GET['client_id'] != "" && $_GET['response_type'] != "" && $_GET['scope'] != "") {
$access_url = $AUTHURL . "?";
foreach($_GET as $name => $value) {
$access_url .= "$name=" . urlencode($value) . "&";
}
$access_url = rtrim ($access_url, "&");
$pid = getmypid();
print "Emacs で OAuth2 を利用する際の Authorization コードを取得します。
<br>\n";
print "以下の URL に手元のブラウザからアクセスしてください。<br>\n";
print "/oauth2/delegate-request.php?p=$pid";
file_put_contents("/tmp/oauth-url." . $pid, $access_url);
} else {
print "エラー: リクエストが不正です。\n";
}
print "</body></html>\n";

0 comments on commit 5db26a7

Please sign in to comment.