Files
vm/controllers/account.go
zeekayandGitHub f7321c9463 build(visor): GOEXPERIMENT=jsonv2 per SCALE_STANDARD (#8)
* refactor: import github.com/hanzoai/iam (drop iamsdk/v2)

Switch from github.com/hanzoai/iamsdk/v2/iamsdk to canonical
github.com/hanzoai/iam root package. One canonical path, no drift.
Pinned to iam@86e34e93 SHA pseudo-version until v1.16.2 ships.

* build(visor): GOEXPERIMENT=jsonv2 in Dockerfile per SCALE_STANDARD

Per SCALE_STANDARD.md §2 — every Go production Dockerfile that emits
JSON to a client builds with GOEXPERIMENT=jsonv2. Verified on
hanzoai/zip's json_bench_test.go:
- Edge POST roundtrip: -12% time, -23% allocs
- Marshal-only: -22% time
- Unmarshal-only: -19% time, -25% allocs

build.sh inherits the ENV from the parent ARG so the existing go-build
invocation picks up jsonv2 unchanged. The conn-memory regression test
is deferred to a follow-up that migrates visor's beego v1.12 listener
to zip per §9 step-1.
2026-05-29 21:05:29 -07:00

78 lines
1.9 KiB
Go

// Copyright 2023 Hanzo Industries Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package controllers
import (
_ "embed"
"github.com/beego/beego"
iam "github.com/hanzoai/iam"
)
//go:embed token_jwt_key.pem
var JwtPublicKey string
func init() {
InitAuthConfig()
}
func InitAuthConfig() {
iamEndpoint := beego.AppConfig.String("iamEndpoint")
clientId := beego.AppConfig.String("clientId")
clientSecret := beego.AppConfig.String("clientSecret")
iamOrganization := beego.AppConfig.String("iamOrganization")
iamApplication := beego.AppConfig.String("iamApplication")
iam.InitConfig(iamEndpoint, clientId, clientSecret, JwtPublicKey, iamOrganization, iamApplication)
}
func (c *ApiController) Signin() {
code := c.Input().Get("code")
state := c.Input().Get("state")
token, err := iam.GetOAuthToken(code, state)
if err != nil {
panic(err)
}
claims, err := iam.ParseJwtToken(token.AccessToken)
if err != nil {
panic(err)
}
claims.AccessToken = token.AccessToken
c.SetSessionClaims(claims)
userId := claims.User.Owner + "/" + claims.User.Name
c.Ctx.Input.SetParam("recordUserId", userId)
c.ResponseOk(claims)
}
func (c *ApiController) Signout() {
c.SetSessionClaims(nil)
c.ResponseOk()
}
func (c *ApiController) GetAccount() {
if c.RequireSignedIn() {
return
}
claims := c.GetSessionClaims()
c.ResponseOk(claims)
}