mirror of
https://github.com/imorland/flarum-ext-oauth-amazon.git
synced 2025-01-07 03:06:41 +08:00
First commit
This commit is contained in:
commit
86da6188e9
19
.editorconfig
Normal file
19
.editorconfig
Normal file
@ -0,0 +1,19 @@
|
||||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.{diff,md}]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{php,xml,json}]
|
||||
indent_size = 4
|
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
js/src export-ignore
|
||||
.git* export-ignore
|
||||
|
||||
js/dist/*.js -diff
|
32
.github/workflows/build.yml
vendored
Executable file
32
.github/workflows/build.yml
vendored
Executable file
@ -0,0 +1,32 @@
|
||||
name: JavaScript
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: JS / Build
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Restore npm cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-node-${{ hashFiles('js/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-node-
|
||||
|
||||
# Our action will install npm, cd into `./js`, run `npm run build` and
|
||||
# `npm run build-typings`, then commit and upload any changes
|
||||
- name: Build production JS
|
||||
uses: flarum/action-build@2
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
build_script: build
|
||||
package_manager: npm
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
vendor
|
||||
node_modules
|
||||
composer.lock
|
9
LICENSE.md
Normal file
9
LICENSE.md
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
README.md
Normal file
30
README.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Log In With Amazon
|
||||
|
||||
![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/ianm/oauth-amazon.svg)](https://packagist.org/packages/ianm/oauth-amazon) [![Total Downloads](https://img.shields.io/packagist/dt/ianm/oauth-amazon.svg)](https://packagist.org/packages/ianm/oauth-amazon)
|
||||
|
||||
A [Flarum](http://flarum.org) extension. Log in to your Flarum forum with Amazon. An addon for [FoF OAuth](https://github.com/friendsofflarum/oauth)
|
||||
|
||||
## Installation
|
||||
|
||||
Install with composer:
|
||||
|
||||
```sh
|
||||
composer require ianm/oauth-amazon:"*"
|
||||
```
|
||||
|
||||
## Updating
|
||||
|
||||
```sh
|
||||
composer update ianm/oauth-amazon
|
||||
```
|
||||
|
||||
## Setup
|
||||
1) Register your site with [Amazon](https://developer.amazon.com/docs/login-with-amazon/register-web.html) and obtain your unique `client_id` and `client_secret`
|
||||
2) Once you have created your security profile for your forum, go to `Web Settings` and enter the redirect URL as provided in this extension's settings page.
|
||||
3) Log in with Amazon!
|
||||
|
||||
## Links
|
||||
|
||||
- [Packagist](https://packagist.org/packages/ianm/oauth-amazon)
|
||||
- [GitHub](https://github.com/ianm/oauth-amazon)
|
||||
- [Discuss](https://discuss.flarum.org/d/PUT_DISCUSS_SLUG_HERE)
|
41
composer.json
Normal file
41
composer.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "ianm/oauth-amazon",
|
||||
"description": "Log in to your Flarum forum with Amazon",
|
||||
"keywords": [
|
||||
"flarum"
|
||||
],
|
||||
"type": "flarum-extension",
|
||||
"license": "MIT",
|
||||
"support": {
|
||||
"issues": "https://github.com/imorland/flarum-ext-oauth-amazon/issues",
|
||||
"source": "https://github.com/imorland/flarum-ext-oauth-amazon",
|
||||
"forum": "https://discuss.flarum.org/d/XXXX"
|
||||
},
|
||||
"require": {
|
||||
"flarum/core": "^1.0.0",
|
||||
"fof/oauth": "^1.1.0",
|
||||
"luchianenco/oauth2-amazon": "^2.0"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "IanM",
|
||||
"homepage": "https://discuss.flarum.org/u/ianm"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"IanM\\OAuthAmazon\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"flarum-extension": {
|
||||
"title": "Log In With Amazon",
|
||||
"category": "feature",
|
||||
"icon": {
|
||||
"name": "fab fa-amazon",
|
||||
"backgroundColor": "#0072e3",
|
||||
"color": "#fff"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
28
extend.php
Normal file
28
extend.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part 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 IanM\OAuthAmazon;
|
||||
|
||||
use Flarum\Extend;
|
||||
use FoF\OAuth\Extend as OAuthExtend;
|
||||
use IanM\OAuthAmazon\Providers\Amazon;
|
||||
|
||||
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(Amazon::class)),
|
||||
];
|
1
js/admin.js
Normal file
1
js/admin.js
Normal file
@ -0,0 +1 @@
|
||||
export * from './src/admin';
|
2
js/dist/admin.js
vendored
Normal file
2
js/dist/admin.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
module.exports=function(t){var n={};function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}return e.m=t,e.c=n,e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:o})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(e.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var r in t)e.d(o,r,function(n){return t[n]}.bind(null,r));return o},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=3)}([function(t,n){t.exports=flarum.core.compat["admin/app"]},function(t,n){t.exports=flarum.core.compat["admin/components/ExtensionPage"]},function(t,n){t.exports=flarum.core.compat["common/components/LinkButton"]},function(t,n,e){"use strict";e.r(n);var o=e(0),r=e.n(o);function a(t,n){return(a=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t})(t,n)}var u=e(1),i=e.n(u),c=e(2),f=e.n(c),p=function(t){var n,e;function o(){return t.apply(this,arguments)||this}e=t,(n=o).prototype=Object.create(e.prototype),n.prototype.constructor=n,a(n,e);var u=o.prototype;return u.oninit=function(n){t.prototype.oninit.call(this,n)},u.content=function(){return[m("div",{className:"container"},m("div",{className:"AmazonOAuthSettingsPage"},m("br",null),m(f.a,{className:"Button",href:r.a.route("extension",{id:"fof-oauth"})},r.a.translator.trans("fof-oauth.admin.configure_button_label"))))]},o}(i.a);r.a.initializers.add("ianm/oauth-amazon",(function(){r.a.extensionData.for("ianm-oauth-amazon").registerPage(p)}))}]);
|
||||
//# sourceMappingURL=admin.js.map
|
1
js/dist/admin.js.map
vendored
Normal file
1
js/dist/admin.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
11873
js/package-lock.json
generated
Normal file
11873
js/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
js/package.json
Normal file
22
js/package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@ianm/oauth-amazon",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"prettier": "@flarum/prettier-config",
|
||||
"dependencies": {
|
||||
"flarum-webpack-config": "^1.0.0",
|
||||
"flarum-tsconfig": "^1.0.0",
|
||||
"@flarum/prettier-config": "^1.0.0",
|
||||
"webpack": "^4.26.0",
|
||||
"webpack-cli": "^3.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.4.1"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "webpack --mode development --watch",
|
||||
"build": "webpack --mode production",
|
||||
"format": "prettier --write src",
|
||||
"format-check": "prettier --check src"
|
||||
}
|
||||
}
|
22
js/src/admin/components/AmazonOAuthPage.js
Normal file
22
js/src/admin/components/AmazonOAuthPage.js
Normal file
@ -0,0 +1,22 @@
|
||||
import app from 'flarum/admin/app';
|
||||
import ExtensionPage from 'flarum/admin/components/ExtensionPage';
|
||||
import LinkButton from 'flarum/common/components/LinkButton';
|
||||
|
||||
export default class AmazonOAuthPage extends ExtensionPage {
|
||||
oninit(vnode) {
|
||||
super.oninit(vnode);
|
||||
}
|
||||
|
||||
content() {
|
||||
return [
|
||||
<div className="container">
|
||||
<div className="AmazonOAuthSettingsPage">
|
||||
<br />
|
||||
<LinkButton className="Button" href={app.route('extension', { id: 'fof-oauth' })}>
|
||||
{app.translator.trans('fof-oauth.admin.configure_button_label')}
|
||||
</LinkButton>
|
||||
</div>
|
||||
</div>,
|
||||
];
|
||||
}
|
||||
}
|
6
js/src/admin/index.js
Normal file
6
js/src/admin/index.js
Normal file
@ -0,0 +1,6 @@
|
||||
import app from 'flarum/admin/app';
|
||||
import AmazonOAuthPage from './components/AmazonOAuthPage';
|
||||
|
||||
app.initializers.add('ianm/oauth-amazon', () => {
|
||||
app.extensionData.for('ianm-oauth-amazon').registerPage(AmazonOAuthPage);
|
||||
});
|
11
js/tsconfig.json
Normal file
11
js/tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "flarum-tsconfig",
|
||||
"include": ["src/**/*"],
|
||||
"compilerOptions": {
|
||||
"declarationDir": "./dist-typings",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
|
||||
}
|
||||
}
|
||||
}
|
1
js/webpack.config.js
Normal file
1
js/webpack.config.js
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('flarum-webpack-config')();
|
9
less/forum.less
Normal file
9
less/forum.less
Normal file
@ -0,0 +1,9 @@
|
||||
.LogInButton--amazon {
|
||||
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
locale/en.yml
Normal file
20
locale/en.yml
Normal file
@ -0,0 +1,20 @@
|
||||
fof-oauth:
|
||||
admin:
|
||||
settings:
|
||||
providers:
|
||||
amazon:
|
||||
description: Register your forum with the Amazon 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_amazon_button: '=> fof-oauth.forum.log_in.with_button'
|
||||
|
||||
providers:
|
||||
amazon: '=> fof-oauth.lib.providers.amazon'
|
||||
|
||||
lib:
|
||||
providers:
|
||||
amazon: Amazon
|
61
src/Providers/Amazon.php
Normal file
61
src/Providers/Amazon.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part 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 IanM\OAuthAmazon\Providers;
|
||||
|
||||
use Flarum\Forum\Auth\Registration;
|
||||
use FoF\OAuth\Provider;
|
||||
use League\OAuth2\Client\Provider\AbstractProvider;
|
||||
use Luchianenco\OAuth2\Client\Provider\Amazon as AmazonProvider;
|
||||
|
||||
class Amazon extends Provider
|
||||
{
|
||||
/**
|
||||
* @var AmazonProvider
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
public function name(): string
|
||||
{
|
||||
return 'amazon';
|
||||
}
|
||||
|
||||
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 AmazonProvider([
|
||||
'clientId' => $this->getSetting('client_id'),
|
||||
'clientSecret' => $this->getSetting('client_secret'),
|
||||
'redirectUri' => $redirectUri
|
||||
]);
|
||||
}
|
||||
|
||||
public function suggestions(Registration $registration, $user, string $token)
|
||||
{
|
||||
$this->verifyEmail($email = $user->getEmail());
|
||||
|
||||
$registration
|
||||
->provideTrustedEmail($email)
|
||||
->setPayload($user->toArray());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user