2024-12-11 01:12:06 +05:30
|
|
|
import AbstractState from './AbstractState';
|
|
|
|
import { AuthContext } from './AuthFlow';
|
|
|
|
import CompleteState from './CompleteState';
|
|
|
|
|
|
|
|
export default class DeviceCodeState extends AbstractState {
|
|
|
|
async resolve(context: AuthContext, payload: { user_code: string }): Promise<void> {
|
|
|
|
const { query } = context.getRequest();
|
|
|
|
|
2024-12-18 03:41:39 +05:30
|
|
|
return context
|
2024-12-11 01:12:06 +05:30
|
|
|
.run('oAuthValidate', {
|
|
|
|
params: {
|
|
|
|
userCode: payload.user_code,
|
|
|
|
},
|
|
|
|
description: query.get('description')!,
|
|
|
|
prompt: query.get('prompt')!,
|
|
|
|
})
|
|
|
|
.then(() => context.setState(new CompleteState()))
|
|
|
|
.catch((err) => {
|
2024-12-18 03:41:39 +05:30
|
|
|
if (['invalid_user_code', 'expired_token', 'used_user_code'].includes(err.error)) {
|
2024-12-11 01:12:06 +05:30
|
|
|
return context.run('setErrors', { [err.parameter]: err.error });
|
|
|
|
}
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|