質問編集履歴
1
router部分とdockerの部分を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,16 +1,122 @@
|
|
1
1
|
#Go(Gin)とnginxで外部にパラメーター付きでリダイレクトさせたい
|
2
2
|
|
3
|
-
ツイッターでログインさせようとしています。
|
3
|
+
ツイッター認可でログインさせようとしています。
|
4
4
|
|
5
5
|
golangのみの`http://localhost:8080/twitter/login`ではログイン処理ができます.
|
6
6
|
|
7
7
|
しかし、nginxを通すと`https://api.twitter.com/oauth/request_token`で処理が通ってしまいます.
|
8
|
+
|
9
|
+
```docker-conpose.yml
|
10
|
+
|
11
|
+
version: '3'
|
12
|
+
|
13
|
+
services:
|
14
|
+
|
15
|
+
api:
|
16
|
+
|
17
|
+
build: ./docker/api
|
18
|
+
|
19
|
+
container_name: golang
|
20
|
+
|
21
|
+
volumes:
|
22
|
+
|
23
|
+
- ./api:/go/src/api
|
24
|
+
|
25
|
+
networks:
|
26
|
+
|
27
|
+
- default
|
28
|
+
|
29
|
+
ports:
|
30
|
+
|
31
|
+
- 5555:8080
|
32
|
+
|
33
|
+
command: 'go run server.go'
|
34
|
+
|
35
|
+
rp:
|
36
|
+
|
37
|
+
build: ./docker/rp
|
38
|
+
|
39
|
+
container_name: nginx
|
40
|
+
|
41
|
+
volumes:
|
42
|
+
|
43
|
+
- ./nginx:/etc/nginx/conf.d/
|
44
|
+
|
45
|
+
ports:
|
46
|
+
|
47
|
+
- 80:80
|
48
|
+
|
49
|
+
networks:
|
50
|
+
|
51
|
+
- default
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
volumes:
|
56
|
+
|
57
|
+
db-store:
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
```go
|
64
|
+
|
65
|
+
# router.go
|
66
|
+
|
67
|
+
import (
|
68
|
+
|
69
|
+
"github.com/gin-gonic/gin"
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
"api/interfaces/controllers"
|
74
|
+
|
75
|
+
)
|
76
|
+
|
77
|
+
var Router *gin.Engine
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
func init() {
|
82
|
+
|
83
|
+
router := gin.Default()
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
router.GET("api/twitter/login", func(c *gin.Context) { controllers.TwitterLogin(c) })
|
88
|
+
|
89
|
+
router.GET("api/twitter/callback", func(c *gin.Context) { controllers.TwitterCallback(c) })
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
Router = router
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
```
|
8
98
|
|
9
99
|
|
10
100
|
|
11
101
|
```go
|
12
102
|
|
13
103
|
# GET("twitter/login", ~~)
|
104
|
+
|
105
|
+
package controller
|
106
|
+
|
107
|
+
import (
|
108
|
+
|
109
|
+
"net/http"
|
110
|
+
|
111
|
+
"os"
|
112
|
+
|
113
|
+
"github.com/dghubble/oauth1"
|
114
|
+
|
115
|
+
"github.com/dghubble/oauth1/twitter"
|
116
|
+
|
117
|
+
)
|
118
|
+
|
119
|
+
|
14
120
|
|
15
121
|
config := oauth1.Config{
|
16
122
|
|