Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
8fb899877b | |||
a21afc9719 | |||
18c2b5986b |
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
FROM alpine as build
|
||||||
|
|
||||||
|
ADD ./build/app /app
|
||||||
|
|
||||||
|
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
|
||||||
|
&& apk --no-cache add ca-certificates
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
# copy the ca-certificate.crt from the build stage
|
||||||
|
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
COPY --from=build /app /app
|
||||||
|
|
||||||
|
EXPOSE 13721
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app"]
|
9
Makefile
9
Makefile
@ -1,7 +1,7 @@
|
|||||||
include .env
|
include .env
|
||||||
include .env.local
|
include .env.local
|
||||||
|
|
||||||
.PHONY: proto
|
.PHONY: build proto
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go run cmd/mp-server/main.go \
|
go run cmd/mp-server/main.go \
|
||||||
@ -15,6 +15,13 @@ clean:
|
|||||||
|
|
||||||
all: api
|
all: api
|
||||||
|
|
||||||
|
build:
|
||||||
|
CGO_ENABLED=0 GOOS="linux" GOARCH="amd64" \
|
||||||
|
go build -o ./build/app -ldflags="-s -w" -tags timetzdata ./cmd/mp-server
|
||||||
|
upx build/app
|
||||||
|
docker build -t esinio/weixin:mp-auth .
|
||||||
|
rm build/app
|
||||||
|
|
||||||
docker.push:
|
docker.push:
|
||||||
docker push esinio/weixin:oauth2
|
docker push esinio/weixin:oauth2
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
pb "git.esin.io/lab/weixin/protobuf/clientapi/mp/auth"
|
pb "git.esin.io/lab/weixin/protobuf/clientapi/mp/auth"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -43,6 +44,7 @@ func run() error {
|
|||||||
http.HandleFunc("/token", h.exchangeToken)
|
http.HandleFunc("/token", h.exchangeToken)
|
||||||
http.HandleFunc("/userinfo", h.getUserinfo)
|
http.HandleFunc("/userinfo", h.getUserinfo)
|
||||||
http.HandleFunc("/userinfo/sync", h.syncUserinfo)
|
http.HandleFunc("/userinfo/sync", h.syncUserinfo)
|
||||||
|
http.HandleFunc("/clientcredential", h.getClientCredential)
|
||||||
|
|
||||||
return http.ListenAndServe(":"+lisPort, nil)
|
return http.ListenAndServe(":"+lisPort, nil)
|
||||||
}
|
}
|
||||||
@ -111,3 +113,12 @@ func (h restHandler) syncUserinfo(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
json.NewEncoder(w).Encode(resp)
|
json.NewEncoder(w).Encode(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h restHandler) getClientCredential(w http.ResponseWriter, r *http.Request) {
|
||||||
|
resp, err := h.client.GetClientCredential(r.Context(), &emptypb.Empty{})
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(resp)
|
||||||
|
}
|
||||||
|
19
db.sql
Normal file
19
db.sql
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
create schema "identity"
|
||||||
|
create table if not exists "user" (
|
||||||
|
id text primary key,
|
||||||
|
openid text unique not null,
|
||||||
|
created_at timestamp with time zone default current_timestamp,
|
||||||
|
updated_at timestamp with time zone default current_timestamp
|
||||||
|
)
|
||||||
|
create table if not exists "user_token" (
|
||||||
|
user_id text primary key,
|
||||||
|
access_token text,
|
||||||
|
expires_in smallint,
|
||||||
|
refresh_token text,
|
||||||
|
scope text
|
||||||
|
)
|
||||||
|
create table if not exists "user_userinfo" (
|
||||||
|
user_id text primary key,
|
||||||
|
nickname text,
|
||||||
|
head_img_url text
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user