MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / authInfo

Method authInfo

pkg/identityserver/entity_access.go:67–350  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

65}
66
67func (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

Callers 15

getRightsMethod · 0.95
assertGatewayRightsMethod · 0.95
notifyInternalMethod · 0.95
notifyAdminsInternalMethod · 0.95
createUserMethod · 0.95
listUsersMethod · 0.95
listGatewaysMethod · 0.95
listApplicationsMethod · 0.95
sendInvitationMethod · 0.95
listInvitationsMethod · 0.95
deleteInvitationMethod · 0.95

Implementers 5

mockInteroppkg/component/interop_test.go
interopServerpkg/joinserver/http_interop.go
noopServerpkg/interop/server.go
mockTargetpkg/interop/server_test.go
interopServerpkg/identityserver/http_interop.go

Calls 15

GetIdsMethod · 0.95
configFromContextMethod · 0.95
FromIncomingContextFunction · 0.92
DecodeFromStringFunction · 0.92
VerifyFunction · 0.92
IsNotFoundFunction · 0.92
FromContextFunction · 0.92
RightsFromFunction · 0.92
SplitTokenFunction · 0.92
ValidateFunction · 0.92
StdTimeFunction · 0.92
AddFieldFunction · 0.92

Tested by

no test coverage detected