Return the appservice 'device' or nil if the token is not an appservice. Returns an error if there was a problem creating a 'device'.
(ctx context.Context, token, appServiceUserID string)
| 444 | // Return the appservice 'device' or nil if the token is not an appservice. Returns an error if there was a problem |
| 445 | // creating a 'device'. |
| 446 | func (a *UserInternalAPI) queryAppServiceToken(ctx context.Context, token, appServiceUserID string) (*api.Device, error) { |
| 447 | // Search for app service with given access_token |
| 448 | var appService *config.ApplicationService |
| 449 | for _, as := range a.AppServices { |
| 450 | if as.ASToken == token { |
| 451 | appService = &as |
| 452 | break |
| 453 | } |
| 454 | } |
| 455 | if appService == nil { |
| 456 | return nil, nil |
| 457 | } |
| 458 | |
| 459 | // Create a dummy device for AS user |
| 460 | dev := api.Device{ |
| 461 | // Use AS dummy device ID |
| 462 | ID: types.AppServiceDeviceID, |
| 463 | // AS dummy device has AS's token. |
| 464 | AccessToken: token, |
| 465 | AppserviceID: appService.ID, |
| 466 | AccountType: api.AccountTypeAppService, |
| 467 | } |
| 468 | |
| 469 | localpart, err := userutil.ParseUsernameParam(appServiceUserID, &a.ServerName) |
| 470 | if err != nil { |
| 471 | return nil, err |
| 472 | } |
| 473 | |
| 474 | if localpart != "" { // AS is masquerading as another user |
| 475 | // Verify that the user is registered |
| 476 | account, err := a.DB.GetAccountByLocalpart(ctx, localpart) |
| 477 | // Verify that the account exists and either appServiceID matches or |
| 478 | // it belongs to the appservice user namespaces |
| 479 | if err == nil && (account.AppServiceID == appService.ID || appService.IsInterestedInUserID(appServiceUserID)) { |
| 480 | // Set the userID of dummy device |
| 481 | dev.UserID = appServiceUserID |
| 482 | return &dev, nil |
| 483 | } |
| 484 | return nil, &api.ErrorForbidden{Message: "appservice has not registered this user"} |
| 485 | } |
| 486 | |
| 487 | // AS is not masquerading as any user, so use AS's sender_localpart |
| 488 | dev.UserID = appService.SenderLocalpart |
| 489 | return &dev, nil |
| 490 | } |
| 491 | |
| 492 | // PerformAccountDeactivation deactivates the user's account, removing all ability for the user to login again. |
| 493 | func (a *UserInternalAPI) PerformAccountDeactivation(ctx context.Context, req *api.PerformAccountDeactivationRequest, res *api.PerformAccountDeactivationResponse) error { |
no test coverage detected