(ctx context.Context)
| 65 | } |
| 66 | |
| 67 | func (is *IdentityServer) authInfo(ctx context.Context) (info *ttnpb.AuthInfoResponse, err error) { |
| 68 | if access, ok := ctx.Value(requestAccessKey).(*requestAccess); ok { |
| 69 | if access.authInfo != nil { |
| 70 | return access.authInfo, nil |
| 71 | } |
| 72 | defer func() { |
| 73 | if err == nil { |
| 74 | access.authInfo = info |
| 75 | } |
| 76 | }() |
| 77 | } |
| 78 | |
| 79 | md := rpcmetadata.FromIncomingContext(ctx) |
| 80 | if md.AuthType == "" { |
| 81 | return &ttnpb.AuthInfoResponse{}, nil |
| 82 | } |
| 83 | |
| 84 | if md.AuthType == gatewaytokens.AuthType { |
| 85 | token, err := gatewaytokens.DecodeFromString(md.AuthValue) |
| 86 | if err != nil { |
| 87 | return nil, err |
| 88 | } |
| 89 | rights, err := gatewaytokens.Verify(ctx, token, is.config.Gateways.TokenValidity, is.KeyService()) |
| 90 | if err != nil { |
| 91 | if errors.IsNotFound(err) { |
| 92 | log.FromContext(ctx).WithField("id", token.KeyId).Warn("Key not found in key vault") |
| 93 | } |
| 94 | return nil, err |
| 95 | } |
| 96 | return &ttnpb.AuthInfoResponse{ |
| 97 | AccessMethod: &ttnpb.AuthInfoResponse_GatewayToken_{ |
| 98 | GatewayToken: &ttnpb.AuthInfoResponse_GatewayToken{ |
| 99 | Rights: ttnpb.RightsFrom(rights.Rights...).Implied().GetRights(), |
| 100 | GatewayIds: token.Payload.GatewayIds, |
| 101 | }, |
| 102 | }, |
| 103 | }, nil |
| 104 | } |
| 105 | |
| 106 | if md.AuthType == clusterauth.AuthType { |
| 107 | if err := clusterauth.Authorized(ctx); err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | return &ttnpb.AuthInfoResponse{ |
| 111 | UniversalRights: ttnpb.AllClusterRights.Implied(), |
| 112 | }, nil |
| 113 | } |
| 114 | if strings.ToLower(md.AuthType) != "bearer" { |
| 115 | return nil, errUnsupportedAuthorization.New() |
| 116 | } |
| 117 | |
| 118 | token := md.AuthValue |
| 119 | tokenType, tokenID, tokenKey, err := auth.SplitToken(token) |
| 120 | if err != nil { |
| 121 | return nil, err |
| 122 | } |
| 123 | |
| 124 | var fetch func(ctx context.Context, st store.Store) error |
no test coverage detected