Skip to content

Commit

Permalink
fix(platform-server): github redirect uri base on host
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN committed Sep 13, 2022
1 parent 67ec89e commit c05ea11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
github: {
clientId: process.env.GITHUB_OAUTH_CLIENT_ID,
clientSecret: process.env.GITHUB_OAUTH_CLIENT_SECRET,
redirectUri: 'http://localhost:8080/oauth2/callback',
redirectUri: '/oauth2/callback',
accessTokenUri: 'https://github.com/login/oauth/access_token',
authorizationUri: 'https://github.com/login/oauth/authorize',
userInfoUri: 'https://api.github.com/user',
Expand Down
18 changes: 9 additions & 9 deletions packages/platform-server/src/modules/auth/providers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ export class GithubOAuthProvider implements OAuthProvider {
constructor(private readonly allConfig: Config) {}

get config() {
return this.allConfig.oauth.github
return this.allConfig
}

getAuthUrl(state?: string) {
return `${this.config.authorizationUri}?${qs.stringify(
return `${this.config.oauth.github.authorizationUri}?${qs.stringify(
{
client_id: this.config.clientId,
client_id: this.config.oauth.github.clientId,
scope: 'read',
response_type: 'user',
redirect_uri: this.config.redirectUri,
redirect_uri: this.config.host + this.config.path + this.config.oauth.github.redirectUri,
state: state,
},
{ encode: true },
Expand All @@ -58,13 +58,13 @@ export class GithubOAuthProvider implements OAuthProvider {

async getToken(code: string) {
try {
const response = await fetch(this.config.accessTokenUri, {
const response = await fetch(this.config.oauth.github.accessTokenUri, {
method: 'POST',
body: qs.stringify({
code,
client_id: this.config.clientId,
client_secret: this.config.clientSecret,
redirect_uri: this.config.redirectUri,
client_id: this.config.oauth.github.clientId,
client_secret: this.config.oauth.github.clientSecret,
redirect_uri: this.config.host + this.config.path + this.config.oauth.github.redirectUri,
}),
headers: {
Accept: 'application/json',
Expand All @@ -86,7 +86,7 @@ export class GithubOAuthProvider implements OAuthProvider {

async getUser(token: string) {
try {
const response = await fetch(this.config.userInfoUri, {
const response = await fetch(this.config.oauth.github.userInfoUri, {
method: 'GET',
headers: {
Authorization: `token ${token}`,
Expand Down

0 comments on commit c05ea11

Please sign in to comment.