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

Method SaveAuthorize

pkg/oauth/storage.go:87–117  ·  view source on GitHub ↗
(data *osin.AuthorizeData)

Source from the content-addressed store, hash-verified

85}
86
87func (s *storage) SaveAuthorize(data *osin.AuthorizeData) error {
88 userSessionIDs := data.UserData.(userData).UserSessionIdentifiers
89 client := data.Client.(osinClient).Client
90 rights := rightsFromScope(data.Scope)
91 err := s.store.Transact(s.ctx, func(ctx context.Context, st oauth_store.Interface) (err error) {
92 _, err = st.Authorize(ctx, &ttnpb.OAuthClientAuthorization{
93 ClientIds: client.GetIds(),
94 UserIds: userSessionIDs.GetUserIds(),
95 Rights: rights,
96 })
97 if err != nil {
98 return err
99 }
100 if data.CreatedAt.IsZero() {
101 data.CreatedAt = time.Now()
102 }
103 _, err = st.CreateAuthorizationCode(ctx, &ttnpb.OAuthAuthorizationCode{
104 ClientIds: client.GetIds(),
105 UserIds: userSessionIDs.GetUserIds(),
106 UserSessionId: userSessionIDs.SessionId,
107 Rights: rights,
108 Code: data.Code,
109 RedirectUri: data.RedirectUri,
110 State: data.State,
111 CreatedAt: timestamppb.New(data.CreatedAt),
112 ExpiresAt: timestamppb.New(data.CreatedAt.Add(time.Duration(data.ExpiresIn) * time.Second)),
113 })
114 return err
115 })
116 return err
117}
118
119func (s *storage) LoadAuthorize(code string) (data *osin.AuthorizeData, err error) {
120 var (

Callers

nothing calls this directly

Calls 11

rightsFromScopeFunction · 0.85
TransactMethod · 0.65
AuthorizeMethod · 0.65
IsZeroMethod · 0.65
NowMethod · 0.65
NewMethod · 0.65
AddMethod · 0.65
GetIdsMethod · 0.45
GetUserIdsMethod · 0.45
DurationMethod · 0.45

Tested by

no test coverage detected