-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 91c2197
Showing
20 changed files
with
477 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
**/.gitattributes export-ignore | ||
**/.gitignore export-ignore | ||
**/.gitmodules export-ignore | ||
**/.github export-ignore | ||
**/.travis export-ignore | ||
**/.travis.yml export-ignore | ||
**/.editorconfig export-ignore | ||
**/.styleci.yml export-ignore | ||
|
||
**/phpunit.xml export-ignore | ||
**/tests export-ignore | ||
|
||
**/js/dist/**/* -diff | ||
**/js/dist/**/* linguist-generated | ||
**/js/dist-typings/**/* -diff | ||
**/js/dist-typings/**/* linguist-generated | ||
**/js/yarn.lock -diff | ||
**/js/package-lock.json -diff | ||
|
||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Log in With Spotify JS | ||
|
||
on: [workflow_dispatch, push, pull_request] | ||
|
||
jobs: | ||
run: | ||
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main | ||
with: | ||
enable_bundlewatch: false | ||
enable_prettier: true | ||
enable_typescript: true | ||
|
||
frontend_directory: ./js | ||
backend_directory: . | ||
js_package_manager: npm | ||
main_git_branch: main | ||
secrets: | ||
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/vendor | ||
composer.lock | ||
composer.phar | ||
|
||
.DS_Store | ||
Thumbs.db | ||
tests/.phpunit.result.cache | ||
/tests/integration/tmp | ||
.vagrant | ||
.idea/* | ||
.vscode | ||
js/coverage-ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Log in With Spotify | ||
|
||
![License](https://img.shields.io/badge/license-MIT-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/datlechin/flarum-oauth-spotify.svg)](https://packagist.org/packages/datlechin/flarum-oauth-spotify) [![Total Downloads](https://img.shields.io/packagist/dt/datlechin/flarum-oauth-spotify.svg)](https://packagist.org/packages/datlechin/flarum-oauth-spotify) | ||
|
||
A [Flarum](http://flarum.org) extension. Spotify oauth provider for Flarum. | ||
|
||
## Installation | ||
|
||
Install with composer: | ||
|
||
```sh | ||
composer require datlechin/flarum-oauth-spotify:"*" | ||
``` | ||
|
||
## Updating | ||
|
||
```sh | ||
composer update datlechin/flarum-oauth-spotify:"*" | ||
php flarum cache:clear | ||
``` | ||
|
||
## Links | ||
|
||
- [Packagist](https://packagist.org/packages/datlechin/flarum-oauth-spotify) | ||
- [GitHub](https://github.com/datlechin/flarum-oauth-spotify) | ||
- [Discuss](https://discuss.flarum.org/d/PUT_DISCUSS_SLUG_HERE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"name": "datlechin/flarum-oauth-spotify", | ||
"description": "Spotify oauth provider for Flarum.", | ||
"keywords": [ | ||
"flarum", | ||
"spotify", | ||
"oauth" | ||
], | ||
"type": "flarum-extension", | ||
"license": "MIT", | ||
"require": { | ||
"flarum/core": "^1.2.0", | ||
"fof/oauth": "^1.4" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Ngo Quoc Dat", | ||
"email": "[email protected]", | ||
"role": "Developer", | ||
"homepage": "https://ngoquocdat.dev" | ||
} | ||
], | ||
"support": { | ||
"source": "https://github.com/datlechin/flarum-oauth-spotify", | ||
"forum": "https://discuss.flarum.org/d/PUT_DISCUSS_SLUG_HERE" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Datlechin\\OAuthSpotify\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"flarum-extension": { | ||
"title": "Log in With Spotify", | ||
"category": "extension", | ||
"icon": { | ||
"name": "fab fa-spotify", | ||
"color": "#fff", | ||
"backgroundColor": "#1db954" | ||
} | ||
}, | ||
"flarum-cli": { | ||
"modules": { | ||
"admin": true, | ||
"forum": false, | ||
"js": true, | ||
"jsCommon": false, | ||
"css": true, | ||
"locale": true, | ||
"gitConf": true, | ||
"githubActions": true, | ||
"prettier": true, | ||
"typescript": true, | ||
"bundlewatch": false, | ||
"backendTesting": false, | ||
"editorConfig": true, | ||
"styleci": false | ||
} | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require-dev": { | ||
"laravel/pint": "^1.13" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of datlechin/flarum-oauth-spotify. | ||
* | ||
* Copyright (c) 2023 Ngo Quoc Dat. | ||
* | ||
* For the full copyright and license information, please view the LICENSE.md | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Datlechin\OAuthSpotify; | ||
|
||
use Datlechin\OAuthSpotify\Providers\Spotify; | ||
use Flarum\Extend; | ||
use FoF\OAuth\Extend\RegisterProvider; | ||
|
||
return [ | ||
|
||
(new Extend\Frontend('admin')) | ||
->js(__DIR__ . '/js/dist/admin.js'), | ||
|
||
(new Extend\Frontend('forum')) | ||
->css(__DIR__ . '/less/forum.less'), | ||
|
||
new Extend\Locales(__DIR__ . '/locale'), | ||
|
||
(new RegisterProvider(Spotify::class)), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.pnp.* | ||
.yarn/* | ||
bun.lockb | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src/admin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@datlechin/flarum-oauth-spotify", | ||
"private": true, | ||
"version": "0.0.0", | ||
"devDependencies": { | ||
"flarum-webpack-config": "^2.0.0", | ||
"webpack": "^5.65.0", | ||
"webpack-cli": "^4.9.1", | ||
"prettier": "^2.5.1", | ||
"@flarum/prettier-config": "^1.0.0", | ||
"flarum-tsconfig": "^1.0.2", | ||
"typescript": "^4.5.4" | ||
}, | ||
"scripts": { | ||
"dev": "webpack --mode development --watch", | ||
"build": "webpack --mode production", | ||
"analyze": "cross-env ANALYZER=true npm run build", | ||
"format": "prettier --write src", | ||
"format-check": "prettier --check src" | ||
}, | ||
"prettier": "@flarum/prettier-config" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import app from 'flarum/admin/app'; | ||
import { ConfigureWithOAuthPage } from '@fof-oauth'; | ||
|
||
app.initializers.add('datlechin/flarum-oauth-spotify', () => { | ||
app.extensionData.for('datlechin-oauth-envato').registerPage(ConfigureWithOAuthPage); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
// 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/*/*/js/dist-typings/@types/**/*", | ||
// <CUSTOM-1> | ||
// </CUSTOM-1> | ||
"@types/**/*" | ||
], | ||
"compilerOptions": { | ||
// This will output typings to `dist-typings` | ||
"declarationDir": "./dist-typings", | ||
"baseUrl": ".", | ||
"paths": { | ||
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"], | ||
// <CUSTOM-2> | ||
// </CUSTOM-2> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = require('flarum-webpack-config')({ | ||
useExtensions: ['fof-oauth'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.LogInButton--spotify { | ||
border-width: 1px; | ||
|
||
.Button--color(#fff, #1DB954); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fof-oauth: | ||
admin: | ||
settings: | ||
providers: | ||
spotify: | ||
description: Register your forum with Spotify {link}. | ||
client_id_label: Client ID | ||
client_secret_label: Client Secret | ||
|
||
forum: | ||
log_in: | ||
with_spotify_button: '=> fof-oauth.forum.log_in.with_button' | ||
|
||
providers: | ||
spotify: '=> fof-oauth.lib.providers.spotify' | ||
|
||
lib: | ||
providers: | ||
spotify: Spotify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Datlechin\OAuthSpotify\Providers; | ||
|
||
use Flarum\Forum\Auth\Registration; | ||
use FoF\OAuth\Provider; | ||
use Illuminate\Support\Arr; | ||
use League\OAuth2\Client\Provider\AbstractProvider; | ||
|
||
class Spotify extends Provider | ||
{ | ||
public function name(): string | ||
{ | ||
return 'spotify'; | ||
} | ||
|
||
public function link(): string | ||
{ | ||
return 'https://developer.spotify.com/dashboard'; | ||
} | ||
|
||
public function fields(): array | ||
{ | ||
return [ | ||
'client_id' => ['required', 'string'], | ||
'client_secret' => ['required', 'string'], | ||
]; | ||
} | ||
|
||
public function provider(string $redirectUri): AbstractProvider | ||
{ | ||
return new SpotifyProvider([ | ||
'clientId' => $this->getSetting('client_id'), | ||
'clientSecret' => $this->getSetting('client_secret'), | ||
'redirectUri' => $redirectUri, | ||
]); | ||
} | ||
|
||
/** | ||
* @param SpotifyResourceOwner $user | ||
*/ | ||
public function suggestions(Registration $registration, $user, string $token): void | ||
{ | ||
$registration | ||
->provideTrustedEmail($user->getEmail()) | ||
->suggestUsername($user->getDisplayName()); | ||
|
||
if ($avatarUrl = Arr::get($user->getImages(), '0.url')) { | ||
$registration->provideAvatar($avatarUrl); | ||
} | ||
|
||
$registration->setPayload($user->toArray()); | ||
} | ||
} |
Oops, something went wrong.