Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(passport): config passport-github behind of proxy #2318

Merged
merged 3 commits into from
Apr 9, 2018

Conversation

thonatos
Copy link
Member

@thonatos thonatos commented Apr 4, 2018

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

@thonatos
Copy link
Member Author

thonatos commented Apr 4, 2018

Egg 部署于 Nginx 之后并启用 SSL, 无法正确获取协议并提示 error=redirect_uri_mismatch

why

how

// {APP_ROOT}/config/config.{env}.js

// proxy
exports.proxy = true;

// passport
exports.passportGithub = {
  key: process.env.EGG_PASSPORT_GITHUB_CLIENT_ID || 'test',
  secret: process.env.EGG_PASSPORT_GITHUB_CLIENT_SECRET || 'test',
  callbackURL: process.env.EGG_PASSPORT_GITHUB_CALLBACK_URL || '/passport/github/callback',
  proxy: process.env.EGG_PROXY === 'proxy',
};
  

nginx

docker-compose.yml

version: '3'
services: 
  proxy:
    image: nginx:stable-alpine
    ports:
      - 80:80
      - 443:443      
    volumes:
      - ./ext/default.conf:/etc/nginx/conf.d/default.conf
      - ~/.acme.sh/*.implements.io:/etc/nginx/ssl/

default.conf

server {
    listen              443 ssl;
    server_name         dockerizer.implements.io;
    ssl_certificate     /etc/nginx/ssl/fullchain.cer;
    ssl_certificate_key /etc/nginx/ssl/*.implements.io.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    location / {
	set $proxied_server {YOUR_IP}:7001;
 	proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-NginX-Proxy true;
        proxy_redirect off;
        proxy_pass http://$proxied_server;
    }    
} 

备注:

  • 更改 {YOUR_ID} 为自己的ip(注意不要用127.0.0.1
  • 证书自行准备

secret: 'your_clientSecret'
secret: 'your_clientSecret',
// callbackURL: '/passport/github/callback',
// proxy: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 proxy 是不是加错了

Copy link
Member Author

@thonatos thonatos Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里还是得加:

  1. config.proxy = true; 是正确设置
  2. utils.jsapp.getundefined, 判断不了 proxy 是否开启
  3. 通过 egg-passport-githuboptions 把 proxy 传给 passport-oauth2 应该算 trick 了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

喔,我以为是下面说的 config.proxy

Copy link
Member Author

@thonatos thonatos Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯,这里是两个选项:

  • config.proxy = true
  • config.passportGithub.proxy = true

线上在跑了,应该没毛病

@popomore
Copy link
Member

popomore commented Apr 4, 2018

确实可以附加一个简化的 nginx 配置。

@thonatos
Copy link
Member Author

thonatos commented Apr 4, 2018

加在上面了,😀

@codecov
Copy link

codecov bot commented Apr 4, 2018

Codecov Report

Merging #2318 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2318   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files          29       29           
  Lines         749      749           
=======================================
  Hits          746      746           
  Misses          3        3

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24d842c...360ae47. Read the comment docs.

@popomore popomore merged commit 33d3951 into master Apr 9, 2018
@popomore popomore deleted the docs-tutorials-passport-github branch April 9, 2018 01:58
popomore pushed a commit that referenced this pull request Apr 9, 2018
docs(passport): config passport-github behind of proxy (#2318)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants