Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
cpluscc committed Jul 27, 2023
0 parents commit 2c8bd07
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 0 deletions.
39 changes: 39 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "cpluscc/oauth-misskey",
"description": "Log in to your Flarum forum with Amazon",
"keywords": [
"flarum", "amazon", "sso", "oauth", "login"
],
"type": "flarum-extension",
"license": "MIT",
"support": {

},
"require": {
"flarum/core": "^1.2.0",
"fof/oauth": "^1.3.0",
"cpluscc/oauth2-misskey": "*"
},
"authors": [
{
"name": "Cpluscc",
"homepage": "https://post.cplus8.com"
}
],
"autoload": {
"psr-4": {
"Cpluscc\\OAuthMisskey\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "Log In With Misskey",
"category": "feature",
"icon": {
"name": "fab fa-amazon",
"backgroundColor": "#0072e3",
"color": "#fff"
}
}
}
}
28 changes: 28 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is a fork of ianm/oauth-amazon.
*
* Copyright (c) 2021 IanM.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Cpluscc\OAuthMisskey;

use Flarum\Extend;
use FoF\OAuth\Extend as OAuthExtend;
use Cpluscc\OAuthMisskey\Providers\Misskey;

return [
(new Extend\Frontend('forum'))
->css(__DIR__.'/less/forum.less'),

(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),

new Extend\Locales(__DIR__.'/locale'),

(new OAuthExtend\RegisterProvider(Misskey::class)),
];
1 change: 1 addition & 0 deletions js/admin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/admin';
2 changes: 2 additions & 0 deletions js/dist/admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js/dist/admin.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@cpluscc/oauth-misskey",
"version": "0.0.0",
"private": true,
"prettier": "@flarum/prettier-config",
"dependencies": {
"flarum-webpack-config": "^2.0.0",
"flarum-tsconfig": "^1.0.2",
"@flarum/prettier-config": "^1.0.0",
"webpack": "^5.72.1",
"webpack-cli": "^4.9.2"
},
"devDependencies": {
"prettier": "^2.6.2"
},
"scripts": {
"dev": "webpack --mode development --watch",
"build": "webpack --mode production",
"format": "prettier --write src",
"format-check": "prettier --check src"
}
}
16 changes: 16 additions & 0 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use Flarum's tsconfig as a starting point
"extends": "flarum-tsconfig",
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
// and also tells your Typescript server to read core's global typings for
// access to `dayjs` and `$` in the global namespace.
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
"compilerOptions": {
// This will output typings to `dist-typings`
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
}
}
}
3 changes: 3 additions & 0 deletions js/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = require('flarum-webpack-config')({
useExtensions: ['fof-oauth'],
});
9 changes: 9 additions & 0 deletions less/forum.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.LogInButton--misskey {
border-top-color: rgb(168, 135, 52);
border-right-color: rgb(156, 126, 49);
border-bottom-color: rgb(132, 106, 41);
border-left-color: rgb(156, 126, 49);
border-width: 1px;

.Button--color(#000, #f0c14b);
}
20 changes: 20 additions & 0 deletions locale/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fof-oauth:
admin:
settings:
providers:
misskey:
description: Register your forum with the Misskey Developer Portal {link}

client_id_label: => fof-oauth.ref.settings.client_id
client_secret_label: => fof-oauth.ref.settings.client_secret

forum:
log_in:
with_misskey_button: '=> fof-oauth.forum.log_in.with_button'

providers:
amazon: '=> fof-oauth.lib.providers.misskey'

lib:
providers:
amazon: Misskey
63 changes: 63 additions & 0 deletions src/Providers/Misskey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* This file is a fork of ianm/oauth-amazon.
*
* Copyright (c) 2021 IanM.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Cpluscc\OAuthMisskey\Providers;

use Flarum\Forum\Auth\Registration;
use FoF\OAuth\Provider;
use League\OAuth2\Client\Provider\AbstractProvider;
use Cpluscc\OAuth2\Client\Provider\Misskey as MisskeyProvider;
use Cpluscc\OAuth2\Client\Provider\MisskeyResourceOwner;

class Misskey extends Provider
{
/**
* @var MisskeyProvider
*/
protected $provider;

public function name(): string
{
return 'misskey';
}

public function link(): string
{
return 'https://developer.amazon.com/docs/login-with-amazon/register-web.html';
}

public function fields(): array
{
return [
'client_id' => 'required',
'client_secret' => 'required',
];
}

public function provider(string $redirectUri): AbstractProvider
{
return $this->provider = new MisskeyProvider([
'clientId' => $this->getSetting('client_id'),
'clientSecret' => $this->getSetting('client_secret'),
'redirectUri' => $redirectUri,
]);
}

public function suggestions(Registration $registration, $user, string $token)
{
/** @var MisskeyResourceOwner $user */
$this->verifyEmail($email = $user->getEmail());

$registration
->provideTrustedEmail($email)
->setPayload($user->toArray());
}
}

0 comments on commit 2c8bd07

Please sign in to comment.