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

Chao/api auth support #9

Merged
merged 3 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func runMode() string {
return *aPort
}

// @contact.name AAStar Support
// @contact.url https://aastar.xyz
// @securityDefinitions.apikey JWT
// @in header
// @name Authorization
// @description Type 'Bearer \<TOKEN\>' to correctly set the AccessToken
// @BasePath /api
func main() {
port := runMode()
_ = routers.SetRouters().Run(port)
Expand Down
4 changes: 4 additions & 0 deletions conf/appsettings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jwt:
security: hello-eth-paymaster
realm: aastar
idkey: id
2 changes: 1 addition & 1 deletion conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
var once sync.Once

type Conf struct {
// TODO: Add Conf Structure Here
Jwt JWT
}

var conf *Conf
Expand Down
28 changes: 28 additions & 0 deletions conf/jwt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package conf

import "sync"

type JWT struct {
Security string
Realm string
IdKey string
}

var jwt *JWT

var onceJwt sync.Once

// GetJwtKey represents jwt object
func GetJwtKey() *JWT {
onceJwt.Do(func() {
if jwt == nil {
j := getConf().Jwt
jwt = &JWT{
Security: j.Security,
Realm: j.Realm,
}
}
})

return jwt
}
97 changes: 89 additions & 8 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
package docs

import "github.com/swaggo/swag"
Expand All @@ -9,18 +10,77 @@ const docTemplate = `{
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"contact": {
"name": "AAStar Support",
"url": "https://aastar.xyz"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/v1/sponsor-user-operation": {
"/api/auth": {
"post": {
"description": "sponsor the userOp",
"description": "Get AccessToken By ApiKey",
"consumes": [
"application/json"
],
"tags": [
"Auth"
],
"parameters": [
{
"description": "AccessToken Model",
"name": "credential",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.ClientCredential"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/get-support-entrypoint": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "get the support entrypoint",
"consumes": [
"application/json"
],
"tags": [
"Sponsor"
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/get-support-strategy": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "get the support strategy",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Sponsor"
],
Expand All @@ -31,9 +91,14 @@ const docTemplate = `{
}
}
},
"/api/v1/validate-user-operation": {
"/api/v1/try-pay-user-operation": {
"post": {
"description": "validate the userOp for sponsor",
"security": [
{
"JWT": []
}
],
"description": "sponsor the userOp",
"consumes": [
"application/json"
],
Expand All @@ -47,6 +112,24 @@ const docTemplate = `{
}
}
}
},
"definitions": {
"models.ClientCredential": {
"type": "object",
"properties": {
"apiKey": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"JWT": {
"description": "Type 'Bearer \\\u003cTOKEN\\\u003e' to correctly set the AccessToken",
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}`

Expand All @@ -60,8 +143,6 @@ var SwaggerInfo = &swag.Spec{
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
RightDelim: "}}",
}

func init() {
Expand Down
92 changes: 87 additions & 5 deletions docs/swagger.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,74 @@
{
"swagger": "2.0",
"info": {
"contact": {}
"contact": {
"name": "AAStar Support",
"url": "https://aastar.xyz"
}
},
"paths": {
"/api/v1/sponsor-user-operation": {
"/api/auth": {
"post": {
"description": "sponsor the userOp",
"description": "Get AccessToken By ApiKey",
"consumes": [
"application/json"
],
"tags": [
"Auth"
],
"parameters": [
{
"description": "AccessToken Model",
"name": "credential",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.ClientCredential"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/get-support-entrypoint": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "get the support entrypoint",
"consumes": [
"application/json"
],
"tags": [
"Sponsor"
],
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/api/v1/get-support-strategy": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "get the support strategy",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Sponsor"
],
Expand All @@ -20,9 +79,14 @@
}
}
},
"/api/v1/validate-user-operation": {
"/api/v1/try-pay-user-operation": {
"post": {
"description": "validate the userOp for sponsor",
"security": [
{
"JWT": []
}
],
"description": "sponsor the userOp",
"consumes": [
"application/json"
],
Expand All @@ -36,5 +100,23 @@
}
}
}
},
"definitions": {
"models.ClientCredential": {
"type": "object",
"properties": {
"apiKey": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"JWT": {
"description": "Type 'Bearer \\\u003cTOKEN\\\u003e' to correctly set the AccessToken",
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}
59 changes: 54 additions & 5 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,73 @@
definitions:
models.ClientCredential:
properties:
apiKey:
type: string
type: object
info:
contact: {}
contact:
name: AAStar Support
url: https://aastar.xyz
paths:
/api/v1/sponsor-user-operation:
/api/auth:
post:
consumes:
- application/json
description: sponsor the userOp
description: Get AccessToken By ApiKey
parameters:
- description: AccessToken Model
in: body
name: credential
required: true
schema:
$ref: '#/definitions/models.ClientCredential'
responses:
"200":
description: OK
tags:
- Auth
/api/v1/get-support-entrypoint:
get:
consumes:
- application/json
description: get the support entrypoint
responses:
"200":
description: OK
security:
- JWT: []
tags:
- Sponsor
/api/v1/get-support-strategy:
get:
consumes:
- application/json
description: get the support strategy
produces:
- application/json
responses:
"200":
description: OK
security:
- JWT: []
tags:
- Sponsor
/api/v1/validate-user-operation:
/api/v1/try-pay-user-operation:
post:
consumes:
- application/json
description: validate the userOp for sponsor
description: sponsor the userOp
responses:
"200":
description: OK
security:
- JWT: []
tags:
- Sponsor
securityDefinitions:
JWT:
description: Type 'Bearer \<TOKEN\>' to correctly set the AccessToken
in: header
name: Authorization
type: apiKey
swagger: "2.0"
Loading
Loading