mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 09:32:51 +00:00
load config from server instead of config file
This commit is contained in:
4
client/app/model/config.ts
Normal file
4
client/app/model/config.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface IConfig {
|
||||
client_id: string;
|
||||
redirect_uri: string;
|
||||
}
|
||||
11
client/app/services/config.service.ts
Normal file
11
client/app/services/config.service.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import axios from '../axios/axios';
|
||||
import { IConfig } from '../model/config';
|
||||
|
||||
const getConfig = async (): Promise<IConfig> => {
|
||||
const res = await axios.get('/api/config');
|
||||
return res.data.data;
|
||||
};
|
||||
|
||||
export const ConfigService = {
|
||||
getConfig,
|
||||
};
|
||||
@@ -1,14 +1,11 @@
|
||||
const config = require('../../../../config/client.secret.json');
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
|
||||
const { bnet_client_id, bnet_redirect_uri } = config;
|
||||
const getUrl = (redirect_uri: string, client_id: string) =>
|
||||
`https://us.battle.net/oauth/authorize?redirect_uri=${redirect_uri}&scope=wow.profile&client_id=${client_id}&response_type=code`;
|
||||
|
||||
// TODO: support for eu etc.
|
||||
const oauthUrl =
|
||||
`https://us.battle.net/oauth/authorize?redirect_uri=` +
|
||||
`${bnet_redirect_uri}&scope=wow.profile&client_id=${bnet_client_id}&response_type=code`;
|
||||
|
||||
const openOuathWindow = () => {
|
||||
window.open(oauthUrl, '_blank', 'resizeable=yes, height=900, width=1200');
|
||||
const openOuathWindow = async () => {
|
||||
const config = await ConfigService.getConfig();
|
||||
window.open(getUrl(config.redirect_uri, config.client_id), '_blank', 'resizeable=yes, height=900, width=1200');
|
||||
};
|
||||
|
||||
export const Oauth = {
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"bnet_client_id": "",
|
||||
"bnet_redirect_uri": ""
|
||||
}
|
||||
15
lib/myapp_web/controllers/config_controller.ex
Normal file
15
lib/myapp_web/controllers/config_controller.ex
Normal file
@@ -0,0 +1,15 @@
|
||||
defmodule MyAppWeb.ConfigController do
|
||||
use MyAppWeb, :controller
|
||||
alias MyAppWeb.Response
|
||||
alias MyApp.Data
|
||||
|
||||
def get_config(conn, _params) do
|
||||
output = %{
|
||||
"client_id": Application.get_env(:myapp, :bnet_client_id),
|
||||
"redirect_uri": Application.get_env(:myapp, :bnet_redirect_uri),
|
||||
}
|
||||
conn
|
||||
|> put_status(200)
|
||||
|> Response.json(output)
|
||||
end
|
||||
end
|
||||
@@ -22,6 +22,8 @@ defmodule MyAppWeb.Router do
|
||||
scope "/api", MyAppWeb do
|
||||
pipe_through [:api]
|
||||
|
||||
get "/config", ConfigController, :get_config
|
||||
|
||||
scope "/user" do
|
||||
post "/authorize", UserController, :authorize
|
||||
post "/login", UserController, :login
|
||||
|
||||
Reference in New Issue
Block a user